Skip to content

AggregateRoot ​

Base class for aggregate roots with domain event support.

Concept ​

An Aggregate Root is a DDD pattern that:

  • Defines transaction boundaries
  • Is the only entry point for modifications
  • Ensures aggregate consistency
  • Raises domain events

Properties ​

PropertyTypeDescription
DomainEventsIReadOnlyCollection<DomainEvent>Pending events

Methods ​

MethodDescription
AddDomainEvent(DomainEvent)Adds event to collection
RemoveDomainEvent(DomainEvent)Removes specific event
ClearDomainEvents()Clears all pending events
RaiseDomainEvent(DomainEvent)Alias for AddDomainEvent

Usage ​

csharp
public class Order : AggregateRoot
{
    public void Complete()
    {
        Status = OrderStatus.Completed;
        RaiseDomainEvent(new OrderCompletedEvent(Id));
    }
}

TenantScopedAggregateRoot ​

For multi-tenant aggregate roots:

csharp
public class Invoice : TenantScopedAggregateRoot
{
    public Invoice(Guid tenantId) : base(tenantId) { }
}

Released under the MIT License.