Class EventSequence
- Namespace
- Cratis.Chronicle.EventSequences
- Assembly
- Cratis.Chronicle.dll
Represents an implementation of IEventSequence for gRPC.
public class EventSequence : IEventSequence
- Inheritance
-
EventSequence
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
Initializes a new instance of the EventSequence class.
Constructors
EventSequence(EventStoreName, EventStoreNamespaceName, EventSequenceId, IChronicleConnection, IEventTypes, IConstraints, IEventSerializer, ICorrelationIdAccessor, IConcurrencyScopeStrategies, ICausationManager, IUnitOfWorkManager, IIdentityProvider, JsonSerializerOptions)
Represents an implementation of IEventSequence for gRPC.
public EventSequence(EventStoreName eventStoreName, EventStoreNamespaceName @namespace, EventSequenceId eventSequenceId, IChronicleConnection connection, IEventTypes eventTypes, IConstraints constraints, IEventSerializer eventSerializer, ICorrelationIdAccessor correlationIdAccessor, IConcurrencyScopeStrategies concurrencyScopeStrategies, ICausationManager causationManager, IUnitOfWorkManager unitOfWorkManager, IIdentityProvider identityProvider, JsonSerializerOptions jsonSerializerOptions)
Parameters
eventStoreNameEventStoreNameName of the event store.
namespaceEventStoreNamespaceNameNamespace for the event store.
eventSequenceIdEventSequenceIdThe identifier of the event sequence.
connectionIChronicleConnectionCratis.Chronicle.Connections.IChronicleConnection for working with the connection to Chronicle.
eventTypesIEventTypesKnown IEventTypes.
constraintsIConstraintsKnown IConstraints.
eventSerializerIEventSerializerThe IEventSerializer for serializing events.
correlationIdAccessorICorrelationIdAccessorICorrelationIdAccessor for getting correlation.
concurrencyScopeStrategiesIConcurrencyScopeStrategiesIConcurrencyScopeStrategies for managing concurrency scopes.
causationManagerICausationManagerICausationManager for getting causation.
unitOfWorkManagerIUnitOfWorkManagerIUnitOfWorkManager for working with the unit of work.
identityProviderIIdentityProviderIIdentityProvider for resolving identity for operations.
jsonSerializerOptionsJsonSerializerOptionsJSON serializer options to use.
Remarks
Initializes a new instance of the EventSequence class.
Properties
AppendOperations
Gets an observable that emits a collection of AppendedEventWithResult after each append operation.
public IObservable<IEnumerable<AppendedEventWithResult>> AppendOperations { get; }
Property Value
Remarks
Both Append(EventSourceId, object, EventStreamType?, EventStreamId?, EventSourceType?, CorrelationId?, IEnumerable<string>?, ConcurrencyScope?, DateTimeOffset?) and AppendMany(EventSourceId, IEnumerable<object>, EventStreamType?, EventStreamId?, EventSourceType?, CorrelationId?, IEnumerable<string>?, ConcurrencyScope?, DateTimeOffset?) emit through this observable. A single-event append emits a collection of one element; a batch append emits the full batch. Subscribers receive the notification after the operation has completed, whether it succeeded or failed. This observable does not fire for transactional appends through ITransactionalEventSequence.
Id
Gets the EventSequenceId for the event sequence.
public EventSequenceId Id { get; }
Property Value
Transactional
Gets the transactional event sequence.
public ITransactionalEventSequence Transactional { get; }
Property Value
Remarks
Use this when you want to typically append events to the event sequence as a transaction that takes place in the same unit of work. This is very useful when you have disperse event sources that you want to append events to in a single transaction, typically within one request. Using this will also mean that any result will be handled by Chronicle infrastructure and bubbled up, typically when using Chronicle with ASP.NET Core.
Methods
Append(EventSourceId, object, EventStreamType?, EventStreamId?, EventSourceType?, CorrelationId?, IEnumerable<string>?, ConcurrencyScope?, DateTimeOffset?)
Append a single event to the event store.
public Task<AppendResult> Append(EventSourceId eventSourceId, object @event, EventStreamType? eventStreamType = null, EventStreamId? eventStreamId = null, EventSourceType? eventSourceType = null, CorrelationId? correlationId = null, IEnumerable<string>? tags = null, ConcurrencyScope? concurrencyScope = null, DateTimeOffset? occurred = null)
Parameters
eventSourceIdEventSourceIdThe EventSourceId to append for.
eventobjectThe event.
eventStreamTypeEventStreamTypeOptional EventStreamType to append to. Defaults to All.
eventStreamIdEventStreamIdOptional EventStreamId to append to. Defaults to Default.
eventSourceTypeEventSourceTypeOptional EventSourceType to append to. Defaults to Default.
correlationIdCorrelationIdOptional CorrelationId of the event. Defaults to Current.
tagsIEnumerable<string>Optional collection of tags to associate with the event. Will be combined with any static tags from the event type.
concurrencyScopeConcurrencyScopeOptional ConcurrencyScope to use for concurrency control. Defaults to None.
occurredDateTimeOffset?Optional DateTimeOffset specifying when the event occurred. If not set, the server will set it to approximately the time of append.
Returns
- Task<AppendResult>
AppendResult with details about whether or not it succeeded and more.
AppendMany(EventSourceId, IEnumerable<object>, EventStreamType?, EventStreamId?, EventSourceType?, CorrelationId?, IEnumerable<string>?, ConcurrencyScope?, DateTimeOffset?)
Append a collection of events to the event store as a transaction.
public Task<AppendManyResult> AppendMany(EventSourceId eventSourceId, IEnumerable<object> events, EventStreamType? eventStreamType = null, EventStreamId? eventStreamId = null, EventSourceType? eventSourceType = null, CorrelationId? correlationId = null, IEnumerable<string>? tags = null, ConcurrencyScope? concurrencyScope = null, DateTimeOffset? occurred = null)
Parameters
eventSourceIdEventSourceIdThe EventSourceId to append for.
eventsIEnumerable<object>Collection of events to append.
eventStreamTypeEventStreamTypeOptional EventStreamType to append to. Defaults to All.
eventStreamIdEventStreamIdOptional EventStreamId to append to. Defaults to Default.
eventSourceTypeEventSourceTypeOptional EventSourceType to append to. Defaults to Default.
correlationIdCorrelationIdOptional CorrelationId of the event. Defaults to Current.
tagsIEnumerable<string>Optional collection of tags to associate with all events. Will be combined with any static tags from the event types.
concurrencyScopeConcurrencyScopeOptional ConcurrencyScope to use for concurrency control. Defaults to None.
occurredDateTimeOffset?Optional DateTimeOffset specifying when the events occurred. If not set, the server will set it to approximately the time of append.
Returns
- Task<AppendManyResult>
AppendManyResult with details about whether or not it succeeded and more.
Remarks
All events will be committed as one operation for the underlying data store.
AppendMany(IEnumerable<EventForEventSourceId>, CorrelationId?, IEnumerable<string>?, IDictionary<EventSourceId, ConcurrencyScope>?)
Append a collection of events to the event store as a transaction.
public Task<AppendManyResult> AppendMany(IEnumerable<EventForEventSourceId> events, CorrelationId? correlationId = null, IEnumerable<string>? tags = null, IDictionary<EventSourceId, ConcurrencyScope>? concurrencyScopes = null)
Parameters
eventsIEnumerable<EventForEventSourceId>Collection of EventForEventSourceId to append.
correlationIdCorrelationIdOptional CorrelationId of the event. Defaults to Current.
tagsIEnumerable<string>Optional collection of tags to associate with all events. Will be combined with any static tags from the event types.
concurrencyScopesIDictionary<EventSourceId, ConcurrencyScope>Optional IDictionary<TKey, TValue> of EventSourceId and ConcurrencyScope to use for concurrency control. Defaults to an empty dictionary.
Returns
- Task<AppendManyResult>
AppendManyResult with details about whether or not it succeeded and more.
Remarks
All events will be committed as one operation for the underlying data store.
GetForEventSourceIdAndEventTypes(EventSourceId, IEnumerable<EventType>, EventStreamType?, EventStreamId?, EventSourceType?)
Get all events for a specific EventSourceId.
public Task<IImmutableList<AppendedEvent>> GetForEventSourceIdAndEventTypes(EventSourceId eventSourceId, IEnumerable<EventType> filterEventTypes, EventStreamType? eventStreamType = null, EventStreamId? eventStreamId = null, EventSourceType? eventSourceType = null)
Parameters
eventSourceIdEventSourceIdEventSourceId to get for.
filterEventTypesIEnumerable<EventType>Collection of EventType to get for.
eventStreamTypeEventStreamTypeOptional EventStreamType to append to. Defaults to All.
eventStreamIdEventStreamIdOptional EventStreamId to append to. Defaults to Default.
eventSourceTypeEventSourceTypeOptional EventSourceType to append to. Defaults to Default.
Returns
- Task<IImmutableList<AppendedEvent>>
A collection of AppendedEvent.
GetFromSequenceNumber(EventSequenceNumber, EventSourceId?, IEnumerable<EventType>?)
Get all events after and including the given EventSequenceNumber with optional EventSourceId and IEnumerable<T> of EventType for filtering.
public Task<IImmutableList<AppendedEvent>> GetFromSequenceNumber(EventSequenceNumber sequenceNumber, EventSourceId? eventSourceId = null, IEnumerable<EventType>? filterEventTypes = null)
Parameters
sequenceNumberEventSequenceNumberThe EventSequenceNumber of the first event to get from.
eventSourceIdEventSourceIdThe optional EventSourceId.
filterEventTypesIEnumerable<EventType>The optional IEnumerable<T> of EventType.
Returns
- Task<IImmutableList<AppendedEvent>>
A collection of AppendedEvent.
GetNextSequenceNumber()
Get the next sequence number.
public Task<EventSequenceNumber> GetNextSequenceNumber()
Returns
- Task<EventSequenceNumber>
Next sequence number.
GetTailSequenceNumber(EventSourceId?, EventSourceType?, EventStreamType?, EventStreamId?, IEnumerable<EventType>?)
Get the sequence number of the last (tail) event in the sequence.
public Task<EventSequenceNumber> GetTailSequenceNumber(EventSourceId? eventSourceId = null, EventSourceType? eventSourceType = null, EventStreamType? eventStreamType = null, EventStreamId? eventStreamId = null, IEnumerable<EventType>? filterEventTypes = null)
Parameters
eventSourceIdEventSourceIdOptional EventSourceId to get for. If not specified, it will return the tail sequence number for all event sources.
eventSourceTypeEventSourceTypeOptional EventSourceType to get for. If not specified, it will return the tail sequence number for all event source types.
eventStreamTypeEventStreamTypeOptional EventStreamType to get for. If not specified, it will return the tail sequence number for all event stream types.
eventStreamIdEventStreamIdOptional EventStreamId to get for. If not specified, it will return the tail sequence number for all event streams.
filterEventTypesIEnumerable<EventType>Optional collection of EventType to filter by. If not specified, it will return the tail sequence number for all.
Returns
- Task<EventSequenceNumber>
Tail sequence number.
GetTailSequenceNumberForObserver(Type)
Get the sequence number of the last (tail) event in the sequence for a specific observer.
public Task<EventSequenceNumber> GetTailSequenceNumberForObserver(Type type)
Parameters
typeTypeType of observer to get for.
Returns
- Task<EventSequenceNumber>
Tail sequence number.
Remarks
This is based on the tail of the event types the observer is interested in.
HasEventsFor(EventSourceId)
Check if there are events for a specific EventSourceId.
public Task<bool> HasEventsFor(EventSourceId eventSourceId)
Parameters
eventSourceIdEventSourceIdEventSourceId to check for.
Returns
Redact(EventSequenceNumber, RedactionReason)
Redact an event at a specific sequence number.
public Task Redact(EventSequenceNumber sequenceNumber, RedactionReason reason)
Parameters
sequenceNumberEventSequenceNumberEventSequenceNumber to redact.
reasonRedactionReasonReason for redacting.
Returns
Redact(EventSourceId, RedactionReason, params Type[])
Redact all events for a specific EventSourceId.
public Task Redact(EventSourceId eventSourceId, RedactionReason reason, params Type[] clrEventTypes)
Parameters
eventSourceIdEventSourceIdEventSourceId to redact.
reasonRedactionReasonReason for redacting.
clrEventTypesType[]Optionally any specific event types.