Interface IAggregateRoot<TAggregate, TKey>
Generic interface for strongly-typed aggregates with factory methods.
public interface IAggregateRoot<TAggregate, TKey> : IAggregateRoot<TKey>, IAggregateRoot where TAggregate : IAggregateRoot<TAggregate, TKey> where TKey : notnull
Type Parameters
TAggregateThe type of the aggregate.
TKeyThe type of the aggregate identifier.
- Inherited Members
Remarks
This interface provides static factory methods for creating aggregates, enabling polymorphic aggregate construction in generic repository implementations.
Methods
Create(TKey)
Creates a new instance of the aggregate.
public static abstract TAggregate Create(TKey id)
Parameters
idTKeyThe unique identifier for the aggregate.
Returns
- TAggregate
A new instance of the aggregate.
FromEvents(TKey, IEnumerable<HistoricEvent>)
Rebuilds the aggregate from a stream of events.
public static abstract TAggregate FromEvents(TKey id, IEnumerable<HistoricEvent> events)
Parameters
idTKeyThe unique identifier for the aggregate.
eventsIEnumerable<HistoricEvent>The stream of events to apply.
Returns
- TAggregate
The aggregate rebuilt from the events.