Interface IImmutableProjectionBuilder<TProjection>
- Namespace
- Excalibur.EventSourcing.Projections
- Assembly
- Excalibur.EventSourcing.dll
Fluent builder for configuring an immutable projection's mode, event handlers, and caching.
public interface IImmutableProjectionBuilder<TProjection> where TProjection : class
Type Parameters
TProjectionThe immutable projection state type. No
new()constraint required -- supports C# records, init-only types, and any immutable data structure.
Remarks
Use WhenCreating for factory methods (first event → new projection) and
WhenTransforming for reducers (existing projection + event → new projection).
Behavior per Q1 decision:
- null current + Creating → factory returns new instance
- null current + Transforming → throws (no state to transform)
- non-null current + Transforming → reducer returns new instance
- non-null current + Creating → factory replaces (last-wins)
Methods
AddImmutableProjectionHandlersFromAssembly(Assembly)
Scans the specified assembly for all implementations of IImmutableProjectionHandler<TProjection, TEvent> and registers them as handlers for this projection.
[RequiresUnreferencedCode("Assembly scanning uses reflection to discover IImmutableProjectionHandler<T, TEvent> implementations.")]
IImmutableProjectionBuilder<TProjection> AddImmutableProjectionHandlersFromAssembly(Assembly assembly)
Parameters
assemblyAssemblyThe assembly to scan.
Returns
- IImmutableProjectionBuilder<TProjection>
This builder for fluent chaining.
Async()
Configures the projection to be applied asynchronously by the projection host. This is the default and, since inline application was removed, the only mode.
IImmutableProjectionBuilder<TProjection> Async()
Returns
- IImmutableProjectionBuilder<TProjection>
This builder for fluent chaining.
Inline()
Applies the committed event prefix before the save returns, with automatic durable recovery.
IImmutableProjectionBuilder<TProjection> Inline()
Returns
- IImmutableProjectionBuilder<TProjection>
This builder.
WhenCreating<TEvent>(Func<TEvent, TProjection>)
Registers a factory handler that creates a new projection from an event.
IImmutableProjectionBuilder<TProjection> WhenCreating<TEvent>(Func<TEvent, TProjection> factory) where TEvent : IDomainEvent
Parameters
factoryFunc<TEvent, TProjection>A function that creates a new projection from the event.
Returns
- IImmutableProjectionBuilder<TProjection>
This builder for fluent chaining.
Type Parameters
TEventThe domain event type.
WhenHandledBy<TEvent, THandler>()
Registers a DI-resolved typed handler for immutable projection transforms.
IImmutableProjectionBuilder<TProjection> WhenHandledBy<TEvent, THandler>() where TEvent : IDomainEvent where THandler : IImmutableProjectionHandler<TProjection, TEvent>
Returns
- IImmutableProjectionBuilder<TProjection>
This builder for fluent chaining.
Type Parameters
TEventThe domain event type.
THandlerThe handler type implementing IImmutableProjectionHandler<TProjection, TEvent>.
WhenTransforming<TEvent>(Func<TProjection, TEvent, TProjection>)
Registers a transform handler that produces a new projection from the current state and an event.
IImmutableProjectionBuilder<TProjection> WhenTransforming<TEvent>(Func<TProjection, TEvent, TProjection> transform) where TEvent : IDomainEvent
Parameters
transformFunc<TProjection, TEvent, TProjection>A function that takes the current projection and event, returning a new projection instance.
Returns
- IImmutableProjectionBuilder<TProjection>
This builder for fluent chaining.
Type Parameters
TEventThe domain event type.
WithCacheTtl(TimeSpan)
Configures optional caching for ephemeral projection results.
IImmutableProjectionBuilder<TProjection> WithCacheTtl(TimeSpan ttl)
Parameters
ttlTimeSpanThe cache time-to-live.
Returns
- IImmutableProjectionBuilder<TProjection>
This builder for fluent chaining.