Domain-Driven Design (DDD)
Tactical Domain-Driven Design in EricksonLopez.* combines EricksonLopez.DomainPrimitives (L0), EricksonLopez.Events.Contracts (L0), EricksonLopez.SharedKernel (L1), and EricksonLopez.ValueObjects (L1) to keep domain invariants enforceable at compile time.
| Concept | Package | Verified Contract |
|---|---|---|
| Strongly-Typed ID | EricksonLopez.DomainPrimitives |
[StrongId<Guid>] / [StrongId<long>] on readonly partial record struct |
| Domain Primitives | EricksonLopez.DomainPrimitives |
[StringPrimitive], [Email], [NumericPrimitive<T>], [SmartEnum<T>] |
| Rich Value Objects | EricksonLopez.ValueObjects |
Money (Fowler Allocate), CurrencyCode, Email, DateRange |
| Entities & Aggregates | EricksonLopez.SharedKernel |
Entity<TId>, AggregateRoot<TId>, DrainDomainEvents() |
| Domain Events | EricksonLopez.Events.Contracts & SharedKernel |
IDomainEvent, DomainEvent abstract record |
[StrongId<Guid>] is the canonical attribute in EricksonLopez.DomainPrimitives for compile-time strongly-typed IDs, and AggregateRoot<TId>.DrainDomainEvents() atomically extracts pending events for dispatch after persistence:
using System;using EricksonLopez.DomainPrimitives;using EricksonLopez.Result;using EricksonLopez.SharedKernel;using EricksonLopez.ValueObjects;
namespace Example.Domain.Billing;
[StrongId<Guid>]public readonly partial record struct InvoiceId;
public sealed record InvoiceIssuedEvent(InvoiceId InvoiceId, Money Total) : DomainEvent;
public sealed class Invoice : AggregateRoot<InvoiceId>{ public Money Total { get; private set; } public bool IsIssued { get; private set; }
private Invoice(InvoiceId id, Money total) : base(id) { Total = total; }
public static Result<Invoice> Create(InvoiceId id, Money total) { if (!total.IsInitialized || total.Amount <= 0m) { return Result.Failure<Invoice>( Error.Validation("Invoice.InvalidTotal", "Invoice total must be positive.")); }
return Result.Success(new Invoice(id, total)); }
public Result Issue() { if (IsIssued) { return Result.Failure( Error.Conflict("Invoice.AlreadyIssued", "Invoice has already been issued.")); }
IsIssued = true; RaiseDomainEvent(new InvoiceIssuedEvent(Id, Total)); return Result.Success(); }}- DomainPrimitives Documentation (
[StrongId<T>], semantic shortcuts, Roslyn diagnosticsDP0001–DP0018) - SharedKernel Documentation (
Entity<TId>,AggregateRoot<TId>, EF Core & Dapper integration) - ValueObjects Documentation (
Money,Percentage,ELVO001–ELVO004) - Events Documentation (
IDomainEvent,EventBus,CloudEvents)