Lewee.Domain 0.40.3

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

Lewee.Domain

Domain layer abstractions for implementing applications using Domain-Driven Design (DDD) principles.

Purpose

This package provides the foundational building blocks for creating domain models following DDD patterns, including entities, aggregate roots, value objects, domain events, specifications, and repository interfaces.

Dependencies

  • MediatR - For domain event notification support

Components

Base Classes

AuditableRecord

Base class for records that track audit information:

Property Type Description
Id Guid Unique identifier
CreatedBy string User who created the record
CreatedAtUtc DateTime UTC timestamp of creation
ModifiedBy string User who last modified the record
ModifiedAtUtc DateTime UTC timestamp of last modification
Entity

Extends AuditableRecord with soft-delete support via the ISoftDeleteEntity interface:

  • IsDeleted property for soft-delete tracking
  • Delete() and Undelete() methods
  • Equality based on Id property
  • Hash code based on type and Id
AggregateRoot

Extends Entity with domain event support:

public class Order : AggregateRoot
{
    public void Complete()
    {
        this.Status = OrderStatus.Completed;
        this.DomainEvents.Raise(new OrderCompletedEvent(correlationId, this.Id));
    }
}

The DomainEventsCollection stores raised events until they are dispatched by Lewee.Infrastructure.Data.

ValueObject<T>

Base class for immutable value objects with equality based on component values:

public class Address : ValueObject<Address>
{
    public string Street { get; }
    public string City { get; }
    
    protected override IEnumerable<object> GetEqualityComponents()
    {
        yield return Street;
        yield return City;
    }
}
Relationship

Base class for many-to-many relationship entities, extending AuditableRecord.

EnumEntity<TKey>

Represents an enum value as a database entity with Id and Name properties, useful for lookup tables.

Domain Events

DomainEvent

Base class for domain events implementing MediatR's INotification:

Property Type Description
CorrelationId Guid Request correlation ID for tracing
UserId string? Optional user ID who triggered the event
EventDateTime DateTime When the event occurred
DomainEventsCollection

Collection for raising and storing domain events on aggregate roots:

this.DomainEvents.Raise(new OrderCreatedEvent(correlationId));
DomainEventReference

Serialized reference to a domain event stored in the database for the outbox pattern.

Interfaces

IRepository<T>

Repository interface for aggregate root data access:

public interface IRepository<T> where T : AggregateRoot
{
    Task<T?> RetrieveByIdAsync(Guid id, CancellationToken cancellationToken = default);
    Task<List<T>> AllAsync(CancellationToken cancellationToken = default);
    Task<List<T>> QueryAsync(QuerySpecification<T> spec, CancellationToken cancellationToken = default);
    Task<T?> QueryOneAsync(QuerySpecification<T> spec, CancellationToken cancellationToken = default);
    Task AddAsync(T entity, CancellationToken cancellationToken = default);
    Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
ISpecification<T>

Generic specification pattern interface for business rule validation:

public class OrderCanBeShippedSpecification : ISpecification<Order>
{
    public bool IsValid(Order order) => order.Status == OrderStatus.Paid;
}
IQueryProjection

Marker interface for query projections with a correlation ID.

IQueryProjectionService

Service interface for executing query projections.

ISoftDeleteEntity

Marker interface for entities supporting soft delete.

IServiceBusEvent

Marker interface for events that should be published to a service bus.

Query Specifications

QuerySpecification<T>

Fluent builder for repository queries with filtering and eager loading:

public class ActiveOrdersByCustomerSpec : QuerySpecification<Order>
{
    public ActiveOrdersByCustomerSpec(Guid customerId)
    {
        Query
            .Where(o => o.CustomerId == customerId)
            .Where(o => !o.IsDeleted)
            .Include(o => o.Items)
            .ThenInclude<OrderItem, Product>(i => i.Product);
    }
}

Exceptions

DomainException

Exception for domain rule violations, caught by DomainExceptionBehavior in Lewee.Application:

throw new DomainException("Order cannot be modified after completion");

Integration with Other Lewee Packages

Package Integration
Lewee.Application DomainExceptionBehavior handles DomainException in MediatR pipeline
Lewee.Infrastructure.Data Implements IRepository<T>, dispatches domain events via outbox pattern
Lewee.Infrastructure.Auth Implements IAuthenticatedUserService from Lewee.Common

Architecture Benefits

  • Clean Domain Model: Entities focus on business logic, not infrastructure
  • Event-Driven: Domain events enable decoupled reactions to state changes
  • Outbox Pattern: Domain events are persisted for reliable async dispatch
  • Specification Pattern: Encapsulate and reuse query logic
  • Soft Delete: Track deleted records without losing data
  • Audit Trail: Automatic tracking of who created/modified records
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Lewee.Domain:

Package Downloads
Lewee.Application

Package Description

Lewee.Infrastructure.Data

Package Description

Lewee.Auth.Domain

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.40.3 58 11/22/2026
0.23.0 425 6/14/2024
0.22.0 365 6/3/2024
0.21.0 472 9/24/2023
0.20.0-alpha.1 138 9/24/2023
0.17.0-alpha.1 178 9/23/2023
0.16.0-alpha.1 177 9/23/2023
0.10.0 377 9/19/2023
0.9.0 388 9/17/2023
0.8.0 413 9/3/2023
0.7.0 433 9/3/2023
0.6.0 412 9/1/2023
0.5.3 411 8/25/2023
0.1.0 505 3/28/2023