ShopSharp.Core.Domain 0.3.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package ShopSharp.Core.Domain --version 0.3.2                
NuGet\Install-Package ShopSharp.Core.Domain -Version 0.3.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ShopSharp.Core.Domain" Version="0.3.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ShopSharp.Core.Domain --version 0.3.2                
#r "nuget: ShopSharp.Core.Domain, 0.3.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ShopSharp.Core.Domain as a Cake Addin
#addin nuget:?package=ShopSharp.Core.Domain&version=0.3.2

// Install ShopSharp.Core.Domain as a Cake Tool
#tool nuget:?package=ShopSharp.Core.Domain&version=0.3.2                

ShopSharp.Core.Domain

Table of Contents

  1. Introduction
  2. Installation
  3. Usage
  4. Examples

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
0.4.1 222 4/1/2023
0.4.0 202 4/1/2023
0.3.3 190 3/30/2023
0.3.2 192 3/30/2023
0.3.1 198 3/30/2023
0.3.0 218 3/28/2023