Skip to main content
Version: 0.15

Aggregate store

Deprecation notice

Since version 0.15, Eventuous doesn't use Aggregate store internally. All persistence operations in command services are using Event store. The following elements are marked obsolete:

  • IAggregateStore interface
  • AggregateStore class
  • AggregateStore<TArchive> class
  • Dependency injection registration methods for Aggregate store

Look in the previous version documentation to learn about IAggregateStore and its usage.

note

Eventuous does not have a concept of Repository. Find out why on this page.

Eventuous provides a number of extensions for IEventReader and IEventWriter interfaces for aggregate persistence.

Storing aggregates

Storing an aggregate instance implies appending new events from the list of changes to the aggregate stream. Functions that allow that are listed below. All those are extensions to IEventWriter interface.

Using stream name

This function requires a pre-calculated stream name to be provided, so it doesn't use any convention for resolving stream names. It uses the provided stream name as-is.

Task<AppendEventsResult> IEventWriter.StoreAggregate<TAggregate, TState>(
StreamName streamName,
TAggregate aggregate,
AmendEvent? amendEvent = null,
CancellationToken cancellationToken = default
)
ParameterTypeDescription
streamNameStreamNameAggregate stream name
aggregateTAggregate<TState>Aggregate instance
amendEventFunc<StreamEvent, StreamEvent>Function that allows adding things like custom metadata
cancellationTokenCancellationTokenCancellation token

Using explicit aggregate id

This function uses the stream name map to convert the provided aggregate identity to a stream name. If the stream name map is not supplied, it will use the default, convention-based calculation (TypeName-Id).

Task<AppendEventsResult> IEventWriter.StoreAggregate<TAggregate, TState, TId>(
TAggregate aggregate,
TId id,
StreamNameMap? streamNameMap = null,
AmendEvent? amendEvent = null,
CancellationToken cancellationToken = default
)
ParameterTypeDescription
aggregateTAggregate<TState>Aggregate instance
idTIdAggregate identity
streamNameMapStreamNameMapMap between identities and stream names
amendEventFunc<StreamEvent, StreamEvent>Function that allows adding things like custom metadata
cancellationTokenCancellationTokenCancellation token

Using aggregate identity from state

This function supports storing aggregates with identity-aware state (State<TId>) and uses the aggregate State.Id property combined with the stream name map to resolve the stream name. If the stream name map is not supplied, it will use convention-based stream name calculation.

Task<AppendEventsResult> IEventWriter.StoreAggregate<TAggregate, TState, TId>(
TAggregate aggregate,
StreamNameMap? streamNameMap = null,
AmendEvent? amendEvent = null,
CancellationToken cancellationToken = default
)
ParameterTypeDescription
aggregateTAggregate<TState, TId>Aggregate instance
streamNameMapStreamNameMapMap between identities and stream names
amendEventFunc<StreamEvent, StreamEvent>Function that allows adding things like custom metadata
cancellationTokenCancellationTokenCancellation token

Loading aggregates

Several extensions for IEventReader interface allow loading aggregates from an event store.

Using stream name

This function requires a pre-calculated stream name to be provided, so it doesn't use any convention for resolving stream names. It uses the provided stream name as-is.

Task<TAggregate> LoadAggregate<TAggregate, TState>(
StreamName streamName,
bool failIfNotFound = true,
AggregateFactoryRegistry? factoryRegistry = null,
CancellationToken cancellationToken = default
)
ParameterTypeDescription
streamNameStreamNameAggregate stream name
failIfNotFoundboolWhen set to true, the function will throw an AggregateNotFound exception if the stream cannot be found. Otherwise, it will return a new aggregate instance.
factoryRegistryAggregateFactoryRegistryOptional aggregate factory registry, which is used to create new aggregate instances. If not supplied, the default registry is used.
cancellationTokenCancellationTokenCancellation token

Using aggregate id

This function uses the stream name map to convert the provided aggregate identity to a stream name. If the stream name map is not supplied, it will use the default, convention-based calculation (TypeName-Id).

Task<TAggregate> IEventWriter.LoadAggregate<TAggregate, TState, TId>(
TId aggregateId,
StreamNameMap? streamNameMap = null,
bool failIfNotFound = true,
AggregateFactoryRegistry? factoryRegistry = null,
CancellationToken cancellationToken = default
)
ParameterTypeDescription
idTIdAggregate identity
streamNameMapStreamNameMapMap between identities and stream names
failIfNotFoundboolWhen set to true, the function will throw an AggregateNotFound exception if the stream cannot be found. Otherwise, it will return a new aggregate instance.
factoryRegistryAggregateFactoryRegistryOptional aggregate factory registry, which is used to create new aggregate instances. If not supplied, the default registry is used.
cancellationTokenCancellationTokenCancellation token

Multi-tier store

Deprecation notice

Since version 0.15, aggregate store with archive is superseded by tiered event store.