Class ExcaliburEventSourcingBuilder
- Namespace
- Excalibur.EventSourcing.DependencyInjection
- Assembly
- Excalibur.EventSourcing.dll
Fluent builder for configuring Excalibur event sourcing services.
public class ExcaliburEventSourcingBuilder : IEventSourcingBuilder
- Inheritance
-
ExcaliburEventSourcingBuilder
- Implements
- Inherited Members
- Extension Methods
Remarks
This builder provides a fluent API for configuring event sourcing infrastructure:
- Repository registration with automatic or explicit factory methods
- Snapshot strategy configuration (interval, time-based, size-based, composite)
- Event store and serializer configuration
- Outbox store integration
Usage:
services.AddExcalibur(x => x.AddEventSourcing(builder => builder
.AddRepository<OrderAggregate, Guid>()
.UseIntervalSnapshots(100)
.UseSnapshotStrategy<CustomStrategy>()));
Constructors
ExcaliburEventSourcingBuilder(IServiceCollection)
Initializes a new instance of the ExcaliburEventSourcingBuilder class.
public ExcaliburEventSourcingBuilder(IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection to configure.
Properties
Services
Gets the service collection being configured.
public IServiceCollection Services { get; }
Property Value
Methods
AddRepository<TAggregate>(Func<string, TAggregate>, Action<EventSourcedRepositoryOptions>?)
Registers an event-sourced repository for an aggregate type with string keys.
public IEventSourcingBuilder AddRepository<TAggregate>(Func<string, TAggregate> aggregateFactory, Action<EventSourcedRepositoryOptions>? configureOptions = null) where TAggregate : class, IAggregateRoot<string>, IAggregateSnapshotSupport
Parameters
aggregateFactoryFunc<string, TAggregate>Factory function to create aggregate instances from a string key.
configureOptionsAction<EventSourcedRepositoryOptions>Optional per-aggregate repository configuration (e.g., outbox staging strategy).
Returns
- IEventSourcingBuilder
The builder for fluent configuration.
Type Parameters
TAggregateThe aggregate type with string identifier.
Remarks
This method registers an IEventSourcedRepository<TAggregate> that automatically upcasts events during aggregate replay when EnableAutoUpcastOnReplay is enabled and IUpcastingPipeline is registered.
AddRepository<TAggregate, TKey>()
Registers an event-sourced repository for an aggregate type that implements IAggregateRoot<TAggregate, TKey> with static factory methods.
public IEventSourcingBuilder AddRepository<TAggregate, TKey>() where TAggregate : class, IAggregateRoot<TAggregate, TKey>, IAggregateSnapshotSupport where TKey : notnull
Returns
- IEventSourcingBuilder
The builder for fluent configuration.
Type Parameters
TAggregateThe aggregate type implementing IAggregateRoot<TAggregate, TKey>.
TKeyThe key type for the aggregate.
Remarks
This overload automatically uses the static Create(TKey) method from IAggregateRoot<TAggregate, TKey> to create
aggregate instances. No factory function is required.
Usage:
services.AddExcalibur(x => x.AddEventSourcing(builder => builder
.AddRepository<OrderAggregate, Guid>())); // Uses OrderAggregate.Create(id)
AddRepository<TAggregate, TKey>(Func<TKey, TAggregate>, Action<EventSourcedRepositoryOptions>?)
Registers an event-sourced repository for an aggregate type with generic key type.
public IEventSourcingBuilder AddRepository<TAggregate, TKey>(Func<TKey, TAggregate> aggregateFactory, Action<EventSourcedRepositoryOptions>? configureOptions = null) where TAggregate : class, IAggregateRoot<TKey>, IAggregateSnapshotSupport where TKey : notnull
Parameters
aggregateFactoryFunc<TKey, TAggregate>Factory function to create aggregate instances from a key.
configureOptionsAction<EventSourcedRepositoryOptions>Optional per-aggregate repository configuration (e.g., outbox staging strategy).
Returns
- IEventSourcingBuilder
The builder for fluent configuration.
Type Parameters
TAggregateThe aggregate type.
TKeyThe key type for the aggregate.
Remarks
Use this method for aggregates with non-string keys (e.g., Guid, int).
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.
public IEventSourcingBuilder RegisterEventTypeAlias(string storedTypeName, Type eventType)
Parameters
storedTypeNamestringThe 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.
eventTypeTypeThe 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.
public IEventSourcingBuilder RegisterEventTypes(params Type[] eventTypes)
Parameters
eventTypesType[]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.")]
public IEventSourcingBuilder RegisterEventTypesFromAssembly(Assembly assembly)
Parameters
assemblyAssemblyThe 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.
public IEventSourcingBuilder RegisterEventTypes<TEvent>()
Returns
- IEventSourcingBuilder
The builder for fluent configuration.
Type Parameters
TEventThe 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.
public IEventSourcingBuilder UseEventStore<TEventStore>() where TEventStore : class, IEventStore
Returns
- IEventSourcingBuilder
The builder for fluent configuration.
Type Parameters
TEventStoreThe event store implementation type.