Class EventStore

Namespace
Cratis.Chronicle
Assembly
Cratis.Chronicle.dll

Represents an implementation of IEventStore.

public class EventStore : IEventStore
Inheritance
EventStore
Implements
Inherited Members
Extension Methods

Constructors

EventStore(EventStoreName, EventStoreNamespaceName, IChronicleConnection, IClientArtifactsProvider, IEventTypeMigrators, ICorrelationIdAccessor, IConcurrencyScopeStrategies, ICausationManager, IIdentityProvider, IJsonSchemaGenerator, INamingPolicy, IServiceProvider, IReactorSideEffectHandlers, IClientArtifactsActivator, bool, JsonSerializerOptions, bool, IOptions<ChronicleOptions>, ILoggerFactory)

Initializes a new instance of the EventStore class.

public EventStore(EventStoreName eventStoreName, EventStoreNamespaceName @namespace, IChronicleConnection connection, IClientArtifactsProvider clientArtifactsProvider, IEventTypeMigrators eventTypeMigrators, ICorrelationIdAccessor correlationIdAccessor, IConcurrencyScopeStrategies concurrencyScopeStrategies, ICausationManager causationManager, IIdentityProvider identityProvider, IJsonSchemaGenerator schemaGenerator, INamingPolicy namingPolicy, IServiceProvider serviceProvider, IReactorSideEffectHandlers reactorSideEffectHandlers, IClientArtifactsActivator artifactActivator, bool autoDiscoverAndRegister, JsonSerializerOptions jsonSerializerOptions, bool enableEventTypeGenerationValidation, IOptions<ChronicleOptions> options, ILoggerFactory loggerFactory)

Parameters

eventStoreName EventStoreName

Name of the event store.

namespace EventStoreNamespaceName

Namespace for the event store.

connection IChronicleConnection

IChronicleConnection for working with the connection to Chronicle.

clientArtifactsProvider IClientArtifactsProvider

IClientArtifactsProvider for getting client artifacts.

eventTypeMigrators IEventTypeMigrators

IEventTypeMigrators for getting event type migrators.

correlationIdAccessor ICorrelationIdAccessor

ICorrelationIdAccessor for getting correlation.

concurrencyScopeStrategies IConcurrencyScopeStrategies

IConcurrencyScopeStrategies for managing concurrency scopes.

causationManager ICausationManager

ICausationManager for getting causation.

identityProvider IIdentityProvider

IIdentityProvider for resolving identity for operations.

schemaGenerator IJsonSchemaGenerator

IJsonSchemaGenerator for generating JSON schemas.

namingPolicy INamingPolicy

INamingPolicy to use for converting names during serialization.

serviceProvider IServiceProvider

IServiceProvider for getting instances of services.

reactorSideEffectHandlers IReactorSideEffectHandlers

IReactorSideEffectHandlers for handling reactor side-effect return values.

artifactActivator IClientArtifactsActivator

IClientArtifactsActivator for creating artifact instances.

autoDiscoverAndRegister bool

Whether to automatically discover and register artifacts.

jsonSerializerOptions JsonSerializerOptions

JsonSerializerOptions for serialization.

enableEventTypeGenerationValidation bool

Whether to enable event type generation chain validation. Defaults to false.

options IOptions<ChronicleOptions>

The IOptions<TOptions> for Chronicle configuration.

loggerFactory ILoggerFactory

ILoggerFactory for creating loggers.

Properties

Connection

Gets the IChronicleConnection used for the IEventStore.

public IChronicleConnection Connection { get; }

Property Value

IChronicleConnection

Constraints

Gets the IConstraints for the event store.

public IConstraints Constraints { get; }

Property Value

IConstraints

Discovery

Gets the artifacts found by the last completed discovery pass, or NotRun. Reading this does not trigger discovery or indicate registration success.

public DiscoveryReport Discovery { get; }

Property Value

DiscoveryReport

EventLog

Gets the IEventLog event sequence.

public IEventLog EventLog { get; }

Property Value

IEventLog

EventSources

Gets the IEventSources for the event store.

public IEventSources EventSources { get; }

Property Value

IEventSources

Exceptions

EventSourcesNotSupported

Thrown when the implementation does not support event sources.

EventTypes

Gets the IEventTypes for the event store.

public IEventTypes EventTypes { get; }

Property Value

IEventTypes

ExternalServices

Gets the IExternalServices for the event store.

public IExternalServices ExternalServices { get; }

Property Value

IExternalServices

FailedPartitions

Gets the IFailedPartitions for the event store.

public IFailedPartitions FailedPartitions { get; }

Property Value

IFailedPartitions

Identities

Gets the IIdentityManager for managing identities for the event store.

public IIdentityManager Identities { get; }

Property Value

IIdentityManager

Jobs

Gets the IJobs for the event store.

public IJobs Jobs { get; }

Property Value

IJobs

Name

Gets the Name for the event store.

public EventStoreName Name { get; }

Property Value

EventStoreName

Namespace

Gets the namespace for the event store.

public EventStoreNamespaceName Namespace { get; }

Property Value

EventStoreNamespaceName

Observers

Gets the IObservers for the event store, for operating on its observers.

public IObservers Observers { get; }

Property Value

IObservers

Remarks

Optional, so that an existing implementation of this interface - a test double, a scenario harness in a consuming framework - keeps compiling and loading without change. Adding a required member to an interface this widely implemented breaks every implementer at type-load time, before any of their code runs. The real event store implements it; anything that does not says so by throwing rather than by quietly answering.

Exceptions

ObserversNotSupported

Thrown when the implementation does not support operating on observers.

Occurrences

Gets occurrence effect receipts bound to this store and namespace.

public IOccurrences Occurrences { get; }

Property Value

IOccurrences

Exceptions

EffectReceiptsNotSupported

This implementation does not support occurrences.

PII

Gets the IPIIManager for managing PII encryption keys (GDPR right-to-erasure) for the event store.

public IPIIManager PII { get; }

Property Value

IPIIManager

Patterns

Gets the IPatterns for the event store.

public IPatterns Patterns { get; }

Property Value

IPatterns

Remarks

Optional, so that an existing implementation of this interface - a test double, a scenario harness in a consuming framework - keeps compiling and loading without change. Adding a required member to an interface this widely implemented breaks every implementer at type-load time, before any of their code runs. The real event store implements it; anything that does not says so by throwing rather than by quietly answering.

Exceptions

PatternsNotSupported

Thrown when the implementation does not support behavior patterns.

Projections

Gets the IProjections for the event store.

public IProjections Projections { get; }

Property Value

IProjections

Reactors

Gets the IReactors for the event store.

public IReactors Reactors { get; }

Property Value

IReactors

ReadModelReactors

Gets the IReadModelReactors for the event store.

public IReadModelReactors ReadModelReactors { get; }

Property Value

IReadModelReactors

ReadModels

Gets the IReadModels for the event store.

public IReadModels ReadModels { get; }

Property Value

IReadModels

Reducers

Gets the IReducers for the event store.

public IReducers Reducers { get; }

Property Value

IReducers

Registration

Gets what became of the declared artifacts the last time RegisterAll() ran.

public RegistrationOutcome Registration { get; }

Property Value

RegistrationOutcome

Remarks

This is NotRun until RegisterAll() has completed, and from then on reports every declared projection artifact as either registered or failed, carrying the failure that stopped it. It is read-only and decides nothing - what a consumer does about a failed artifact is the consumer's call.

Registration is wired to the connection lifecycle, so it runs on its own; reading this property never triggers it. To block until it has run, use RegistrationWaitExtensions.WaitForRegistration. Do not poll IsConnected as a substitute - see RegistrationOutcome for why that races.

Seeding

Gets the IEventSeeding for the event store.

public IEventSeeding Seeding { get; }

Property Value

IEventSeeding

Subscriptions

Gets the IEventStoreSubscriptions for the event store.

public IEventStoreSubscriptions Subscriptions { get; }

Property Value

IEventStoreSubscriptions

UnitOfWorkManager

Gets the IClientArtifactsProvider for the event store.

public IUnitOfWorkManager UnitOfWorkManager { get; }

Property Value

IUnitOfWorkManager

Webhooks

Gets the IWebhooks for the event store.

public IWebhooks Webhooks { get; }

Property Value

IWebhooks

Methods

DiscoverAll()

Discover all artifacts for the event store.

public Task DiscoverAll()

Returns

Task

Awaitable task.

GetEventSequence(EventSequenceId)

Get an event sequence by id.

public IEventSequence GetEventSequence(EventSequenceId id)

Parameters

id EventSequenceId

The identifier of the event sequence to get.

Returns

IEventSequence

IEventSequence instance.

GetNamespaces(CancellationToken)

List namespaces in the event store.

public Task<IEnumerable<EventStoreNamespaceName>> GetNamespaces(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional CancellationToken.

Returns

Task<IEnumerable<EventStoreNamespaceName>>

An asynchronous enumerable for all namespace names.

RegisterAll()

Register all artifacts for the event store.

public Task RegisterAll()

Returns

Task

Awaitable task.

Remarks

Runs as a single flight per event store: a call that arrives while a run is in flight - a reconnect firing while startup registration is still on the wire, or any operation re-triggering connect after a failed run - joins that run instead of sending the kernel a second copy of the same registration. A run that follows a failed one waits an exponentially growing, jittered backoff first, so a kernel that is too slow to accept the registration sees the retry pressure back off instead of pile up. The flight is created lazily so an instance materialized without its constructor - as specification harnesses do - still registers correctly.

RemoveNamespace(EventStoreNamespaceName, CancellationToken)

Remove a namespace from the event store, together with its observers, their reminders and the data Chronicle stores for it. Clients connected to the namespace must stop using it first. Removing a namespace that does not exist does nothing; the default namespace cannot be removed.

public Task RemoveNamespace(EventStoreNamespaceName @namespace, CancellationToken cancellationToken = default)

Parameters

namespace EventStoreNamespaceName

The EventStoreNamespaceName to remove.

cancellationToken CancellationToken

Optional CancellationToken.

Returns

Task

Awaitable task.

Exceptions

NotSupportedException

The event store does not support removing namespaces.