Table of Contents

Interface IEventSourcingBuilder

Namespace
Excalibur.EventSourcing.DependencyInjection
Assembly
Excalibur.EventSourcing.dll

Fluent builder interface for configuring Excalibur event sourcing services.

public interface IEventSourcingBuilder
Extension Methods

Examples

services.AddExcalibur(x => x.AddEventSourcing(builder =>
{
    builder.AddRepository<OrderAggregate, Guid>()
           .UseIntervalSnapshots(100)
           .UseEventStore<SqlServerEventStore>();
}));

Remarks

This interface follows the Microsoft-style fluent builder pattern, consistent with IOutboxBuilder and ICdcBuilder.

All methods return this for method chaining, enabling a fluent configuration experience.

Properties

Services

Gets the service collection being configured.

IServiceCollection Services { get; }

Property Value

IServiceCollection

The IServiceCollection.

Methods

AddRepository<TAggregate>(Func<string, TAggregate>, Action<EventSourcedRepositoryOptions>?)

Registers an event-sourced repository for an aggregate type with string keys.

IEventSourcingBuilder AddRepository<TAggregate>(Func<string, TAggregate> aggregateFactory, Action<EventSourcedRepositoryOptions>? configureOptions = null) where TAggregate : class, IAggregateRoot<string>, IAggregateSnapshotSupport

Parameters

aggregateFactory Func<string, TAggregate>

Factory function to create aggregate instances from a string key.

configureOptions Action<EventSourcedRepositoryOptions>

Optional per-aggregate repository configuration (e.g., outbox staging strategy).

Returns

IEventSourcingBuilder

The builder for fluent configuration.

Type Parameters

TAggregate

The aggregate type with string identifier.

AddRepository<TAggregate, TKey>()

Registers an event-sourced repository for an aggregate type that implements IAggregateRoot<TAggregate, TKey> with static factory methods.

IEventSourcingBuilder AddRepository<TAggregate, TKey>() where TAggregate : class, IAggregateRoot<TAggregate, TKey>, IAggregateSnapshotSupport where TKey : notnull

Returns

IEventSourcingBuilder

The builder for fluent configuration.

Type Parameters

TAggregate

The aggregate type.

TKey

The key type for the aggregate.

AddRepository<TAggregate, TKey>(Func<TKey, TAggregate>, Action<EventSourcedRepositoryOptions>?)

Registers an event-sourced repository for an aggregate type with generic key type.

IEventSourcingBuilder AddRepository<TAggregate, TKey>(Func<TKey, TAggregate> aggregateFactory, Action<EventSourcedRepositoryOptions>? configureOptions = null) where TAggregate : class, IAggregateRoot<TKey>, IAggregateSnapshotSupport where TKey : notnull

Parameters

aggregateFactory Func<TKey, TAggregate>

Factory function to create aggregate instances from a key.

configureOptions Action<EventSourcedRepositoryOptions>

Optional per-aggregate repository configuration.

Returns

IEventSourcingBuilder

The builder for fluent configuration.

Type Parameters

TAggregate

The aggregate type.

TKey

The key type for the aggregate.

RegisterEventTypeAlias(string, Type)

Registers a stored type name that an event type used to be written under, so events already in the store keep resolving after the type moves namespace or assembly.

IEventSourcingBuilder RegisterEventTypeAlias(string storedTypeName, Type eventType)

Parameters

storedTypeName string

The type name exactly as it appears in the store's event-type column, including the assembly, version, culture and public key token if they were recorded.

eventType Type

The type that name should now resolve to.

Returns

IEventSourcingBuilder

The builder for fluent configuration.

Remarks

Affects resolution only: new events are still written under the type's current name. Register an upcaster as well if the event's shape changed and not just its name.

RegisterEventTypes(params Type[])

Registers the specified event types in the secure event-type allow-list.

IEventSourcingBuilder RegisterEventTypes(params Type[] eventTypes)

Parameters

eventTypes Type[]

The event types to register.

Returns

IEventSourcingBuilder

The builder for fluent configuration.

RegisterEventTypesFromAssembly(Assembly)

Registers every IDomainEvent type in assembly in the secure event-type allow-list.

[RequiresUnreferencedCode("Scans the assembly for IDomainEvent types via reflection, which is not trim-safe. Use RegisterEventTypes<TEvent>() or RegisterEventTypes(params Type[]) for a trim/AOT-safe path.")]
IEventSourcingBuilder RegisterEventTypesFromAssembly(Assembly assembly)

Parameters

assembly Assembly

The assembly to scan (typically typeof(Program).Assembly).

Returns

IEventSourcingBuilder

The builder for fluent configuration.

Remarks

A compile-time-known, consumer-controlled DI-time scan — categorically different from the runtime reflection scan the serializer rejects by default. The security guarantee is unchanged; this removes the risk of hand-listing and missing an event type.

RegisterEventTypes<TEvent>()

Registers TEvent in the secure event-type allow-list consulted by the default serializer, at the event-sourcing wiring call site.

IEventSourcingBuilder RegisterEventTypes<TEvent>()

Returns

IEventSourcingBuilder

The builder for fluent configuration.

Type Parameters

TEvent

The event type to register.

Remarks

The default serializer rejects unregistered event types for security; registering them here gives it a secure and functional resolution path (mirrors JsonSerializerContext opt-in). Equivalent to services.AddEventTypes<TEvent>(), discoverable at the builder.

UseEventStore<TEventStore>()

Configures a custom event store implementation.

IEventSourcingBuilder UseEventStore<TEventStore>() where TEventStore : class, IEventStore

Returns

IEventSourcingBuilder

The builder for fluent configuration.

Type Parameters

TEventStore

The event store implementation type.