Table of Contents

Class ImmutableProjectionServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Excalibur.EventSourcing.dll

Extension methods for registering immutable projections on IEventSourcingBuilder.

public static class ImmutableProjectionServiceCollectionExtensions
Inheritance
ImmutableProjectionServiceCollectionExtensions
Inherited Members

Methods

AddImmutableProjection<TProjection>(IEventSourcingBuilder, Action<IImmutableProjectionBuilder<TProjection>>)

Registers an immutable projection with the event notification system.

[RequiresUnreferencedCode("Implementations serialize the projection type reflectively; supply JsonSerializerOptions with a source-generated resolver for trimming and AOT.")]
[RequiresDynamicCode("Implementations serialize the projection type reflectively; supply JsonSerializerOptions with a source-generated resolver for trimming and AOT.")]
public static IEventSourcingBuilder AddImmutableProjection<TProjection>(this IEventSourcingBuilder builder, Action<IImmutableProjectionBuilder<TProjection>> configure) where TProjection : class

Parameters

builder IEventSourcingBuilder

The event sourcing builder.

configure Action<IImmutableProjectionBuilder<TProjection>>

Action to configure the immutable projection handlers.

Returns

IEventSourcingBuilder

The builder for fluent chaining.

Type Parameters

TProjection

The immutable projection state type. No new() constraint -- supports C# records, init-only types, and any reference type.

Examples

builder.AddImmutableProjection<OrderSummaryRecord>(p => p
    .Async()
    .WhenCreating<OrderPlaced>(e => new OrderSummaryRecord(e.AggregateId, e.Amount, "Placed"))
    .WhenTransforming<OrderShipped>((proj, e) => proj with { Status = "Shipped" }));

Remarks

Use WhenCreating for factory methods (first event → new projection) and WhenTransforming for reducers (existing projection + event → new projection).