Interface IImmutableProjectionHandler<TProjection, TEvent>
- Namespace
- Excalibur.EventSourcing
- Assembly
- Excalibur.EventSourcing.Abstractions.dll
Defines a typed, DI-resolved event handler for immutable projection transforms.
public interface IImmutableProjectionHandler<TProjection, in TEvent> where TProjection : class where TEvent : IDomainEvent
Type Parameters
TProjectionThe immutable projection state type (e.g., a C# record).
TEventThe domain event type this handler processes.
Remarks
Unlike IProjectionEventHandler<TProjection, TEvent> which mutates state in-place, this handler returns a new projection instance (functional transform pattern).
The current parameter on TransformAsync(TProjection?, TEvent, ProjectionHandlerContext, CancellationToken) is null
when this is the first event for a projection ID. Handlers should create a new
instance (factory) or throw depending on their semantics.
Methods
TransformAsync(TProjection?, TEvent, ProjectionHandlerContext, CancellationToken)
Transforms the projection state by producing a new instance from the current state and the event.
Task<TProjection> TransformAsync(TProjection? current, TEvent @event, ProjectionHandlerContext context, CancellationToken cancellationToken)
Parameters
currentTProjectionThe current projection state, or null if no projection exists for this ID yet (creation scenario).
eventTEventThe domain event to process.
contextProjectionHandlerContextContext providing aggregate metadata and optional projection ID override.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<TProjection>
A new projection instance representing the updated state.