Nera.Lib.Domain 1.0.5

dotnet add package Nera.Lib.Domain --version 1.0.5
                    
NuGet\Install-Package Nera.Lib.Domain -Version 1.0.5
                    
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="Nera.Lib.Domain" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nera.Lib.Domain" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Nera.Lib.Domain" />
                    
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 Nera.Lib.Domain --version 1.0.5
                    
#r "nuget: Nera.Lib.Domain, 1.0.5"
                    
#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 Nera.Lib.Domain@1.0.5
                    
#: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=Nera.Lib.Domain&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Nera.Lib.Domain&version=1.0.5
                    
Install as a Cake Tool

Nera.Lib.Domain

.NET 9.0 NuGet License: MIT

A comprehensive .NET 9 library providing domain-driven design (DDD) building blocks for Nera applications. This library includes essential domain modeling constructs such as entities, value objects, aggregates, domain events, and CQRS patterns.

Features

🏗️ Domain Building Blocks

  • Entities: Base classes for domain entities with built-in auditing and tracking
  • Value Objects: Immutable objects distinguished by their state
  • Aggregates: Aggregate root implementation with domain event support
  • Domain Events: Event-driven architecture support with MediatR integration

🔄 CQRS Support

  • Command Handlers: Base classes for command processing
  • Query Handlers: Base classes for query processing
  • Behaviors: Logging and validation pipeline behaviors
  • Domain Event Handlers: Reactive event processing

📦 Repository Patterns

  • Generic Repository: Standard CRUD operations
  • Read/Write Separation: Separate read and write repositories
  • Specification Pattern: Query specification support
  • Unit of Work: Transaction management

🎯 Additional Features

  • Auditable Entities: Automatic tracking of creation and modification
  • Multi-tenant Support: Built-in tenant isolation
  • Pagination: Standardized pagination utilities
  • Filters & Sorting: Query filtering and ordering capabilities
  • Outbox Pattern: Reliable event publishing

Installation

Install the package via NuGet Package Manager:

dotnet add package Nera.Lib.Domain

Or via Package Manager Console:

Install-Package Nera.Lib.Domain

Quick Start

1. Creating an Entity

using Nera.Lib.Domain.Entities;

public class Product : BaseEntity<Guid>
{
    public string Name { get; private set; }
    public decimal Price { get; private set; }
    
    public Product(string name, decimal price)
    {
        Name = name;
        Price = price;
    }
    
    public void UpdatePrice(decimal newPrice)
    {
        if (newPrice <= 0)
            throw new ArgumentException("Price must be positive");
            
        Price = newPrice;
        // Domain event will be automatically tracked
        AddDomainEvent(new ProductPriceChangedEvent(Id, newPrice));
    }
}

2. Creating a Value Object

using Nera.Lib.Domain.ValueObjects;

public class Money : ValueObject
{
    public decimal Amount { get; }
    public string Currency { get; }
    
    public Money(decimal amount, string currency)
    {
        Amount = amount;
        Currency = currency;
    }
    
    protected override IEnumerable<object> GetEqualityComponents()
    {
        yield return Amount;
        yield return Currency;
    }
}

3. Creating an Aggregate Root

using Nera.Lib.Domain.Aggregates;

public class Order : AggregateRoot<Guid>
{
    private readonly List<OrderItem> _items = new();
    
    public string OrderNumber { get; private set; }
    public OrderStatus Status { get; private set; }
    public IReadOnlyList<OrderItem> Items => _items.AsReadOnly();
    
    public Order(string orderNumber)
    {
        OrderNumber = orderNumber;
        Status = OrderStatus.Draft;
        
        AddDomainEvent(new OrderCreatedEvent(Id, orderNumber));
    }
    
    public void AddItem(Product product, int quantity)
    {
        var item = new OrderItem(product.Id, quantity, product.Price);
        _items.Add(item);
        
        AddDomainEvent(new OrderItemAddedEvent(Id, item.ProductId, quantity));
    }
}

4. Using CQRS

using Nera.Lib.Domain.CQRS;

// Command
public record CreateProductCommand(string Name, decimal Price) : ICommand<Guid>;

// Command Handler
public class CreateProductHandler : BaseCommandHandler<CreateProductCommand, Guid>
{
    private readonly IRepository<Product> _repository;
    
    public CreateProductHandler(IRepository<Product> repository)
    {
        _repository = repository;
    }
    
    protected override async Task<Guid> ExecuteAsync(
        CreateProductCommand request, 
        CancellationToken cancellationToken)
    {
        var product = new Product(request.Name, request.Price);
        await _repository.AddAsync(product, cancellationToken);
        return product.Id;
    }
}

5. Repository Usage

using Nera.Lib.Domain.Repositories;

public interface IProductRepository : IRepository<Product>
{
    Task<IEnumerable<Product>> GetByPriceRangeAsync(decimal min, decimal max);
}

public class ProductRepository : IProductRepository
{
    // Implementation using your preferred ORM
}

Architecture Components

Entity Hierarchy

IEntity<TKey>
├── BaseEntity<TKey>
│   ├── AuditableEntity<TKey>
│   └── Entity<TKey>
└── AggregateRoot<TKey>

Event System

  • Domain Events: Business events that occur within aggregates
  • Event Publisher: Publishes events to registered handlers
  • Event Handlers: Process domain events reactively

Repository Pattern

  • IReadRepository: Read-only operations
  • IWriteRepository: Write operations
  • IRepository: Combined read/write interface
  • ISpecification: Query specifications

Configuration

Dependency Injection

// Program.cs or Startup.cs
services.AddScoped<IRepository<Product>, ProductRepository>();
services.AddScoped<IUnitOfWork, UnitOfWork>();

// Register MediatR for CQRS
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));

Entity Framework Integration

public class ApplicationDbContext : DbContext
{
    public DbSet<Product> Products { get; set; }
    
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Configure your entities
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);
    }
}

Best Practices

  1. Domain Events: Use domain events for cross-aggregate communication
  2. Value Objects: Prefer value objects for concepts without identity
  3. Aggregates: Keep aggregates small and focused
  4. Repository: Use specifications for complex queries
  5. CQRS: Separate read and write operations for better performance

Dependencies

  • .NET 9.0: Target framework
  • MediatR.Contracts: For CQRS pattern implementation
  • Nera.Lib.Core: Core utilities and extensions

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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

Support

For support and questions, please:

  • Create an issue in the repository
  • Contact the Nextera Systems team
  • Review the documentation and examples

Authors

Nextera Systems - Initial work and maintenance


Part of the Nera Libraries ecosystem for building robust, scalable applications.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Nera.Lib.Domain:

Package Downloads
Nera.Lib.Infrastructure

Infrastructure services and implementations for Nera applications

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 1,177 8/3/2025
1.0.4 99 8/2/2025
1.0.3 108 8/2/2025
1.0.2 523 7/27/2025
1.0.1 193 7/27/2025
1.0.0 218 7/27/2025