Class EventStream
- Namespace
- Stratara.Infrastructure.EventSourcing
- Assembly
- Stratara.Infrastructure.dll
Replay-helper that builds aggregates from event lists by invoking their Apply methods.
Compiled Expression delegates are cached per (aggregateType, eventType) pair
so reflection only happens once per pairing.
public static class EventStream
- Inheritance
-
EventStream
- Inherited Members
Remarks
The dispatcher first tries an Apply(TData) method matching the runtime
Data type; if none exists, it falls back to Apply(IEvent<TData>).
Missing Apply overloads are silently ignored so aggregates can opt in to specific event types.
Methods
Aggregate(Type, IReadOnlyList<IEvent>)
Builds a new aggregate of the given runtime type and applies the events.
public static object Aggregate(Type aggregateType, IReadOnlyList<IEvent> events)
Parameters
aggregateTypeTypeConcrete aggregate type (must be activatable via ObjectFactory).
eventsIReadOnlyList<IEvent>Events to replay onto the new instance.
Returns
- object
The fully-applied aggregate instance.
Exceptions
- InvalidOperationException
Thrown when an instance of
aggregateTypecannot be created.
Aggregate<TAggregate>(IReadOnlyList<IEvent>)
Builds a new aggregate of type TAggregate and applies the given events.
public static TAggregate Aggregate<TAggregate>(IReadOnlyList<IEvent> events) where TAggregate : notnull, new()
Parameters
eventsIReadOnlyList<IEvent>Events to replay onto the freshly-created aggregate.
Returns
- TAggregate
The fully-applied aggregate instance.
Type Parameters
TAggregateAggregate type with a public parameterless constructor.
ApplyEvents(object, IReadOnlyList<IEvent>)
Applies a sequence of events to an existing aggregate instance in order.
public static void ApplyEvents(this object aggregate, IReadOnlyList<IEvent> events)
Parameters
aggregateobjectTarget aggregate instance.
eventsIReadOnlyList<IEvent>Events to replay in declaration order.