Fermion.Domain.Core 0.0.4

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Fermion.Domain.Core --version 0.0.4
                    
NuGet\Install-Package Fermion.Domain.Core -Version 0.0.4
                    
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="Fermion.Domain.Core" Version="0.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fermion.Domain.Core" Version="0.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Fermion.Domain.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fermion.Domain.Core --version 0.0.4
                    
#r "nuget: Fermion.Domain.Core, 0.0.4"
                    
#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.
#:package Fermion.Domain.Core@0.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fermion.Domain.Core&version=0.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Fermion.Domain.Core&version=0.0.4
                    
Install as a Cake Tool

Fermion.Domain.Core

Overview

Fermion.Domain.Core is a comprehensive package providing essential domain primitives for building robust Domain-Driven Design (DDD) applications. It offers a rich set of base classes and interfaces for creating domain entities, aggregate roots, and implementing advanced patterns like auditing, soft-delete, and domain events.

Features

  • Entity and Aggregate Root Base Classes: Fully-featured base classes implementing DDD concepts
  • Domain Events: Support for local and distributed domain events
  • Comprehensive Auditing: Track creation, modification, and deletion with user context
  • Soft Delete Capability: Entities can be marked as deleted without physical removal
  • Concurrency Control: Built-in concurrency stamp support
  • Correlation Tracking: Support for correlation IDs, session IDs, and application snapshot IDs
  • Flexible ID Types: Generic support for different ID types (Guid, int, string, etc.)
  • DTO Base Classes: Corresponding data transfer object base classes

Installation

# Via Package Manager
Install-Package Fermion.Domain.Core

# Via .NET CLI
dotnet add package Fermion.Domain.Core

Usage

Basic Entity and Aggregate Root

// Define an aggregate root with Guid as key type
public class Customer : AggregateRoot<Guid>
{
    public string Name { get; private set; }
    public string Email { get; private set; }
    
    private List<Order> _orders = new List<Order>();
    public IReadOnlyCollection<Order> Orders => _orders.AsReadOnly();
    
    protected Customer() { } // For ORM
    
    public Customer(Guid id, string name, string email) : base(id)
    {
        Name = name;
        Email = email;
    }
    
    public void UpdateEmail(string email)
    {
        if (string.IsNullOrEmpty(email))
            throw new ArgumentException("Email cannot be empty");
            
        Email = email;
        
        // Raise a domain event
        AddLocalEvent(new CustomerEmailChangedEvent(Id, Email));
    }
    
    public void AddOrder(Order order)
    {
        _orders.Add(order);
        AddDistributedEvent(new OrderAddedEvent(Id, order.Id));
    }
}

// Define a related entity
public class Order : Entity<Guid>
{
    public Guid CustomerId { get; private set; }
    public decimal Amount { get; private set; }
    
    protected Order() { } // For ORM
    
    public Order(Guid id, Guid customerId, decimal amount) : base(id)
    {
        CustomerId = customerId;
        Amount = amount;
    }
}

Using Audited Entities

// Define an entity with full audit support
public class Product : FullAuditedAggregateRoot<Guid>
{
    public string Name { get; private set; }
    public decimal Price { get; private set; }
    
    protected Product() { } // For ORM
    
    public Product(Guid id, string name, decimal price) : base(id)
    {
        Name = name;
        Price = price;
    }
    
    public void UpdatePrice(decimal newPrice)
    {
        Price = newPrice;
    }
}

Working with Domain Events

// Define a domain event
public class OrderAddedEvent
{
    public Guid CustomerId { get; }
    public Guid OrderId { get; }
    
    public OrderAddedEvent(Guid customerId, Guid orderId)
    {
        CustomerId = customerId;
        OrderId = orderId;
    }
}

// Somewhere in your application service or command handler
public async Task CreateOrderAsync(CreateOrderCommand command)
{
    var customer = await _customerRepository.GetByIdAsync(command.CustomerId);
    var order = new Order(Guid.NewGuid(), command.CustomerId, command.Amount);
    
    customer.AddOrder(order);
    
    await _customerRepository.UpdateAsync(customer);
    
    // The domain events will be automatically dispatched by your infrastructure layer
}

Hierarchy of Classes

The package provides a rich hierarchy of base classes:

  • Entity: Basic entity with ID
  • BasicAggregateRoot: Adds domain events capability
  • AggregateRoot: Adds concurrency and extra properties
  • CreationAuditedAggregateRoot: Tracks creation time and creator
  • AuditedAggregateRoot: Adds modification time and modifier
  • FullAuditedAggregateRoot: Adds soft-delete with deletion time and deleter

Interfaces

The package includes various interfaces for specific capabilities:

  • IEntity: Base entity interface
  • IAggregateRoot: Marker interface for aggregate roots
  • IHasConcurrencyStamp: For entities with concurrency control
  • IHasExtraProperties: For entities with dynamic properties
  • IGeneratesDomainEvents: For entities that generate domain events
  • ICreationAuditedObject: Tracks creation information
  • IModificationAuditedObject: Tracks modification information
  • ISoftDelete: For soft-delete capability
  • IFullAuditedObject: Combines all auditing interfaces

Best Practices

  • Use the most specific base class for your needs
  • Implement rich domain models with encapsulated logic
  • Use domain events for cross-aggregate communication
  • Keep aggregate boundaries consistent
  • Use the auditing interfaces to automatically track changes

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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