Skip to main content
Table of Contents

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.

public static IServiceCollection AddEventSourcing(this IServiceCollection services)

Parameters

services IServiceCollection

The 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.

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

services IServiceCollection

The 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.