Class EventSourcingServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Stratara.Infrastructure.dll
Service-collection extensions for the Stratara event-sourcing runtime and the event-stream hashing worker.
public static class EventSourcingServiceCollectionExtensions
- Inheritance
-
EventSourcingServiceCollectionExtensions
- Inherited Members
Methods
AddEventSourcing(IServiceCollection)
Registers the core event-sourcing services as scoped: IEventSource,
IAggregationService, IChangeSetHandler, IEventTypeResolver,
and ISnapshotService. Also contributes the default
VersionThresholdSnapshotStrategy via TryAddSingleton, and the default
event-upcaster pipeline and trusted-type resolver where none is registered.
public static IServiceCollection AddEventSourcing(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The same service collection for chaining.
Examples
Pair it with a write store; on its own it registers the services but nothing to persist through:
services.AddEventSourcing();
services.AddNpgsqlWriteDbContextFactory<AppWriteDbContext>();
Remarks
To control the snapshot cadence — vary it per aggregate type, change the threshold, or disable snapshots with NoSnapshotStrategy — register your own singleton ISnapshotStrategy. A custom registration overrides the default.
This call registers no IStoreConflictDetector: the store registration that
knows the provider does — AddNpgsqlWriteDbContextFactory for PostgreSQL, the
test-support store for SQLite. A host that registers its write context another way, or
brings another provider, registers a detector itself; without one, a duplicate stream
version is not recognised as a ConcurrencyException.
The call reads EventSourcingOptions from the EventSourcing section of the
configuration the container holds, where it holds one:
EventSourcing:AppendAgainstAggregatedVersion (default false) makes every append that follows
a rebuild through IAggregationService conditional on the version that rebuild saw;
EventSourcing:NewStreamOwnerFromSession (Allow, the default, Warn or Refuse)
decides what happens when a new stream's first event would take its owner from the session. A value
that names no policy fails the host's start. The section is read at the position of the first call, so
a Configure<EventSourcingOptions> that must win over it comes after this call.
AddEventStreamHashWorker(IServiceCollection)
Registers Stratara.Infrastructure.EventSourcing.EventStreamHashWorker as a hosted service and the supporting IEventStreamHashService / IEventChainService implementations.
public static IServiceCollection AddEventStreamHashWorker(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The same service collection for chaining.
Examples
services.AddEventStreamHashWorker();
Remarks
Only one host across the deployment should run the hash worker. The worker computes SHA-256 chain hashes over committed events and writes periodic anchors; running it on multiple hosts can produce duplicate anchors and hash-update conflicts.