Table of Contents

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

eventStoreName EventStoreName

Name of the event store.

namespace EventStoreNamespaceName

Namespace for the event store.

eventSequenceId EventSequenceId

The identifier of the event sequence.

connection IChronicleConnection

Cratis.Chronicle.Connections.IChronicleConnection for working with the connection to Chronicle.

eventTypes IEventTypes

Known IEventTypes.

constraints IConstraints

Known IConstraints.

eventSerializer IEventSerializer

The IEventSerializer for serializing events.

correlationIdAccessor ICorrelationIdAccessor

ICorrelationIdAccessor for getting correlation.

concurrencyScopeStrategies IConcurrencyScopeStrategies

IConcurrencyScopeStrategies for managing concurrency scopes.

causationManager ICausationManager

ICausationManager for getting causation.

unitOfWorkManager IUnitOfWorkManager

IUnitOfWorkManager for working with the unit of work.

identityProvider IIdentityProvider

IIdentityProvider for resolving identity for operations.

jsonSerializerOptions JsonSerializerOptions

JSON 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

IObservable<IEnumerable<AppendedEventWithResult>>

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

EventSequenceId

Transactional

Gets the transactional event sequence.

public ITransactionalEventSequence Transactional { get; }

Property Value

ITransactionalEventSequence

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

eventSourceId EventSourceId

The EventSourceId to append for.

event object

The event.

eventStreamType EventStreamType

Optional EventStreamType to append to. Defaults to All.

eventStreamId EventStreamId

Optional EventStreamId to append to. Defaults to Default.

eventSourceType EventSourceType

Optional EventSourceType to append to. Defaults to Default.

correlationId CorrelationId

Optional CorrelationId of the event. Defaults to Current.

tags IEnumerable<string>

Optional collection of tags to associate with the event. Will be combined with any static tags from the event type.

concurrencyScope ConcurrencyScope

Optional ConcurrencyScope to use for concurrency control. Defaults to None.

occurred DateTimeOffset?

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

eventSourceId EventSourceId

The EventSourceId to append for.

events IEnumerable<object>

Collection of events to append.

eventStreamType EventStreamType

Optional EventStreamType to append to. Defaults to All.

eventStreamId EventStreamId

Optional EventStreamId to append to. Defaults to Default.

eventSourceType EventSourceType

Optional EventSourceType to append to. Defaults to Default.

correlationId CorrelationId

Optional CorrelationId of the event. Defaults to Current.

tags IEnumerable<string>

Optional collection of tags to associate with all events. Will be combined with any static tags from the event types.

concurrencyScope ConcurrencyScope

Optional ConcurrencyScope to use for concurrency control. Defaults to None.

occurred DateTimeOffset?

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

events IEnumerable<EventForEventSourceId>

Collection of EventForEventSourceId to append.

correlationId CorrelationId

Optional CorrelationId of the event. Defaults to Current.

tags IEnumerable<string>

Optional collection of tags to associate with all events. Will be combined with any static tags from the event types.

concurrencyScopes IDictionary<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

eventSourceId EventSourceId

EventSourceId to get for.

filterEventTypes IEnumerable<EventType>

Collection of EventType to get for.

eventStreamType EventStreamType

Optional EventStreamType to append to. Defaults to All.

eventStreamId EventStreamId

Optional EventStreamId to append to. Defaults to Default.

eventSourceType EventSourceType

Optional 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

sequenceNumber EventSequenceNumber

The EventSequenceNumber of the first event to get from.

eventSourceId EventSourceId

The optional EventSourceId.

filterEventTypes IEnumerable<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

eventSourceId EventSourceId

Optional EventSourceId to get for. If not specified, it will return the tail sequence number for all event sources.

eventSourceType EventSourceType

Optional EventSourceType to get for. If not specified, it will return the tail sequence number for all event source types.

eventStreamType EventStreamType

Optional EventStreamType to get for. If not specified, it will return the tail sequence number for all event stream types.

eventStreamId EventStreamId

Optional EventStreamId to get for. If not specified, it will return the tail sequence number for all event streams.

filterEventTypes IEnumerable<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

type Type

Type 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

eventSourceId EventSourceId

EventSourceId to check for.

Returns

Task<bool>

True if it has, false if not.

Redact(EventSequenceNumber, RedactionReason)

Redact an event at a specific sequence number.

public Task Redact(EventSequenceNumber sequenceNumber, RedactionReason reason)

Parameters

sequenceNumber EventSequenceNumber

EventSequenceNumber to redact.

reason RedactionReason

Reason for redacting.

Returns

Task

Awaitable Task.

Redact(EventSourceId, RedactionReason, params Type[])

Redact all events for a specific EventSourceId.

public Task Redact(EventSourceId eventSourceId, RedactionReason reason, params Type[] clrEventTypes)

Parameters

eventSourceId EventSourceId

EventSourceId to redact.

reason RedactionReason

Reason for redacting.

clrEventTypes Type[]

Optionally any specific event types.

Returns

Task

Awaitable Task.