ShopSharp.Core.Domain
0.3.3
See the version list below for details.
dotnet add package ShopSharp.Core.Domain --version 0.3.3
NuGet\Install-Package ShopSharp.Core.Domain -Version 0.3.3
<PackageReference Include="ShopSharp.Core.Domain" Version="0.3.3" />
paket add ShopSharp.Core.Domain --version 0.3.3
#r "nuget: ShopSharp.Core.Domain, 0.3.3"
// Install ShopSharp.Core.Domain as a Cake Addin #addin nuget:?package=ShopSharp.Core.Domain&version=0.3.3 // Install ShopSharp.Core.Domain as a Cake Tool #tool nuget:?package=ShopSharp.Core.Domain&version=0.3.3
ShopSharp.Core.Domain
Table of Contents
Introduction
ShopSharp.Core.Domain
is a NuGet package that provides core components of the ShopSharp domain layer.
Installation
To install the ShopSharp.Core.Domain
NuGet package, run the following command in your Package Manager Console:
Install-Package ShopSharp.Core.Domain
Alternatively, you can search for ShopSharp.Core.Domain
in the NuGet Package Manager UI and install from there.
Usage
DomainEvent
DomainEvent
is an abstract record representing an event that occurs in the domain model.
It serves as the base record for custom domain events.
AggregateRoot
AggregateRoot
is an abstract class representing an aggregate root in the domain model.
It is responsible for managing and applying domain events to the aggregate root.
It also keeps track of uncommitted domain events and provides a method to mark them as committed.
Examples
Creating a Custom Domain Event
To create a custom domain event, derive a new record from the DomainEvent
abstract record:
using ShopSharp.Core.Domain.Aggregates;
public record OrderPlaced(Guid OrderId, DateTime OrderDate) : DomainEvent;
Creating an Aggregate Root
To create an aggregate root, derive a new class from the AggregateRoot
abstract class and implement the ApplyDomainEvent
method:
using ShopSharp.Core.Domain.Aggregates;
public class Order : AggregateRoot
{
public Guid Id { get; private set; }
public DateTime OrderDate { get; private set; }
public void PlaceOrder(Guid id, DateTime orderDate)
{
AddAndApplyDomainEvent(new OrderPlaced(id, orderDate));
}
protected override void ApplyDomainEvent(DomainEvent domainEvent)
{
switch (domainEvent)
{
case OrderPlaced orderPlaced:
Id = orderPlaced.OrderId;
OrderDate = orderPlaced.OrderDate;
break;
default:
throw new NotImplementedException();
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.