Interface IAggregateSnapshotSupport
Provides snapshot and history replay capabilities for an aggregate root.
public interface IAggregateSnapshotSupport
Remarks
This interface is separated from IAggregateRoot following the Interface Segregation Principle (ISP). Not all consumers of aggregates need snapshot or history replay capabilities; many only need core event sourcing operations (raising events, reading uncommitted events, committing).
Implementations that support snapshots should implement both IAggregateRoot and IAggregateSnapshotSupport. The AggregateRoot<TKey> base class implements both interfaces.
Properties
AggregateType
Gets the type name of the aggregate for persistence.
string AggregateType { get; }
Property Value
- string
The type name of the aggregate for persistence.
ETag
Gets or sets the ETag for optimistic concurrency control.
string? ETag { get; set; }
Property Value
- string
The ETag value representing the current state version, or null if not set. Used for detecting concurrent modifications when saving aggregates.
Methods
CreateSnapshot()
Creates a snapshot of the current aggregate state.
ISnapshot CreateSnapshot()
Returns
- ISnapshot
A snapshot representing the current state.
Remarks
This method may require runtime type inspection and dynamic code generation, which are not compatible with Native AOT compilation scenarios. Consider using source generation for snapshot creation in AOT-compiled applications.
LoadFromHistory(IEnumerable<HistoricEvent>)
Loads the aggregate state from a history of events.
void LoadFromHistory(IEnumerable<HistoricEvent> history)
Parameters
historyIEnumerable<HistoricEvent>The sequence of historical events to replay, each paired with the authoritative stream version the event store assigned to it.
Remarks
This method replays events to rebuild aggregate state without adding them to the uncommitted events collection. Use this for event sourcing replay. The version is read from the envelope rather than the event payload, so an event that does not carry its own position replays correctly.
LoadFromSnapshot(ISnapshot)
Loads the aggregate state from a snapshot.
void LoadFromSnapshot(ISnapshot snapshot)
Parameters
snapshotISnapshotThe snapshot to load from.