Class EventStoreExtensions
- Namespace
- Opossum.Extensions
- Assembly
- Opossum.dll
Extension methods for IEventStore to provide convenient overloads and helpers
public static class EventStoreExtensions
- Inheritance
-
EventStoreExtensions
- Inherited Members
Methods
AppendAsync(IEventStore, NewEvent, AppendCondition?, CancellationToken)
Appends a single event to the event store
public static Task AppendAsync(this IEventStore eventStore, NewEvent @event, AppendCondition? condition = null, CancellationToken cancellationToken = default)
Parameters
eventStoreIEventStoreThe event store
eventNewEventThe new event to append
conditionAppendConditionOptional append condition for optimistic concurrency control
cancellationTokenCancellationTokenA token to cancel the asynchronous operation
Returns
- Task
A task representing the asynchronous operation
AppendAsync(IEventStore, NewEvent[], CancellationToken)
Appends multiple events to the event store without an append condition
public static Task AppendAsync(this IEventStore eventStore, NewEvent[] events, CancellationToken cancellationToken = default)
Parameters
eventStoreIEventStoreThe event store
eventsNewEvent[]The new events to append
cancellationTokenCancellationTokenA token to cancel the asynchronous operation
Returns
- Task
A task representing the asynchronous operation
AppendEventAsync(IEventStore, IEvent, IEnumerable<Tag>?, Metadata?, AppendCondition?, CancellationToken)
Appends a single domain event to the event store with simplified syntax
public static Task AppendEventAsync(this IEventStore eventStore, IEvent @event, IEnumerable<Tag>? tags = null, Metadata? metadata = null, AppendCondition? condition = null, CancellationToken cancellationToken = default)
Parameters
eventStoreIEventStoreThe event store
eventIEventThe domain event to append
tagsIEnumerable<Tag>Optional tags to attach to the event
metadataMetadataOptional metadata (timestamp and correlation ID auto-generated if not provided)
conditionAppendConditionOptional append condition for optimistic concurrency control
cancellationTokenCancellationTokenA token to cancel the asynchronous operation
Returns
- Task
A task representing the asynchronous operation
AppendEventsAsync(IEventStore, IEvent[], IEnumerable<Tag>?, Metadata?, AppendCondition?, CancellationToken)
Appends multiple domain events to the event store with simplified syntax
public static Task AppendEventsAsync(this IEventStore eventStore, IEvent[] events, IEnumerable<Tag>? tags = null, Metadata? metadata = null, AppendCondition? condition = null, CancellationToken cancellationToken = default)
Parameters
eventStoreIEventStoreThe event store
eventsIEvent[]The domain events to append
tagsIEnumerable<Tag>Optional tags to attach to all events
metadataMetadataOptional metadata (timestamp and correlation ID auto-generated if not provided)
conditionAppendConditionOptional append condition for optimistic concurrency control
cancellationTokenCancellationTokenA token to cancel the asynchronous operation
Returns
- Task
A task representing the asynchronous operation
BuildProjections<TProjection>(SequencedEvent[], Func<SequencedEvent, string>, Func<IEvent, TProjection?, TProjection?>)
Builds projection objects by grouping events by a shared key and folding them sequentially.
Each unique key value produces one projection instance — equivalent to a GroupBy followed by a left-fold.
public static IEnumerable<TProjection> BuildProjections<TProjection>(this SequencedEvent[] events, Func<SequencedEvent, string> keySelector, Func<IEvent, TProjection?, TProjection?> applyEvent) where TProjection : class
Parameters
eventsSequencedEvent[]Events to process
keySelectorFunc<SequencedEvent, string>Function that extracts the grouping key from each event. All events returning the same key are folded into a single projection instance. In DCB terms this is typically the value of a domain identity tag (e.g. the value of a
studentIdtag).applyEventFunc<IEvent, TProjection, TProjection>Function to apply an event to the current projection state (null on the first event for each key)
Returns
- IEnumerable<TProjection>
Enumerable of built projections, one per unique key value
Type Parameters
TProjectionThe projection type to build
Examples
var students = events.BuildProjections<StudentShortInfo>(
keySelector: e => e.Event.Tags.First(t => t.Key == "studentId").Value,
applyEvent: (evt, current) => evt switch
{
StudentRegisteredEvent registered => new StudentShortInfo(...),
StudentUpdatedEvent updated when current != null => current with { ... },
_ => current
}
);
ReadAsync(IEventStore, Query)
Reads events from the event store without any read options
public static Task<SequencedEvent[]> ReadAsync(this IEventStore eventStore, Query query)
Parameters
eventStoreIEventStoreThe event store
queryQueryThe query to filter events
Returns
- Task<SequencedEvent[]>
A task representing the asynchronous operation returning the matching events
ReadAsync(IEventStore, Query, ReadOption)
Reads events from the event store with a single read option
public static Task<SequencedEvent[]> ReadAsync(this IEventStore eventStore, Query query, ReadOption readOption)
Parameters
eventStoreIEventStoreThe event store
queryQueryThe query to filter events
readOptionReadOptionOptional read option (e.g., Descending)
Returns
- Task<SequencedEvent[]>
A task representing the asynchronous operation returning the matching events
ReadAsync(IEventStore, Query, long)
Reads events from the event store that were appended after fromPosition,
without any read options. Useful for incrementally polling new events from a known checkpoint.
public static Task<SequencedEvent[]> ReadAsync(this IEventStore eventStore, Query query, long fromPosition)
Parameters
eventStoreIEventStoreThe event store
queryQueryThe query to filter events
fromPositionlongOnly events with
Position > fromPositionare returned. Pass the last processed sequence position to receive only new events.
Returns
- Task<SequencedEvent[]>
A task representing the asynchronous operation returning the matching events