Class EventNotificationServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Excalibur.EventSourcing.dll
Extension methods for registering projections and event notification services on IEventSourcingBuilder.
public static class EventNotificationServiceCollectionExtensions
- Inheritance
-
EventNotificationServiceCollectionExtensions
- Inherited Members
Methods
AddEventNotificationHandlersFromAssembly(IEventSourcingBuilder, Assembly)
Scans the specified assembly for types implementing IEventNotificationHandler<TEvent> and registers each discovered handler via TryAddEnumerable(IServiceCollection, ServiceDescriptor).
[RequiresUnreferencedCode("Assembly scanning uses reflection to discover IEventNotificationHandler<T> implementations.")]
[RequiresDynamicCode("Implementations serialize the projection type reflectively; supply JsonSerializerOptions with a source-generated resolver for trimming and AOT.")]
public static IEventSourcingBuilder AddEventNotificationHandlersFromAssembly(this IEventSourcingBuilder builder, Assembly assembly)
Parameters
builderIEventSourcingBuilderThe event sourcing builder.
assemblyAssemblyThe assembly to scan for notification handler implementations.
Returns
- IEventSourcingBuilder
The builder for fluent chaining.
Examples
services.AddExcalibur(x => x.AddEventSourcing(builder =>
{
builder.AddEventNotificationHandlersFromAssembly(typeof(OrderNotificationHandler).Assembly);
}));
Remarks
This provides consistency with AddProjectionsFromAssembly(IEventSourcingBuilder, Assembly) by allowing convention-based registration of notification handlers.
AddProjection<TProjection>(IEventSourcingBuilder, Action<IProjectionBuilder<TProjection>>)
Registers a 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 AddProjection<TProjection>(this IEventSourcingBuilder builder, Action<IProjectionBuilder<TProjection>> configure) where TProjection : class, new()
Parameters
builderIEventSourcingBuilderThe event sourcing builder.
configureAction<IProjectionBuilder<TProjection>>Action to configure the projection mode, event handlers, and options.
Returns
- IEventSourcingBuilder
The builder for fluent chaining.
Type Parameters
TProjectionThe projection state type.
Examples
services.AddExcalibur(x => x.AddEventSourcing(builder =>
{
builder.AddProjection<OrderSummary>(p => p
.Async()
.When<OrderPlaced>((proj, e) => { proj.Total = e.Amount; })
.When<OrderShipped>((proj, e) => { proj.ShippedAt = e.ShippedAt; }));
}));
Remarks
A second call for the same projection type replaces the first.
If UseEventNotification(IEventSourcingBuilder) has not been called, this method automatically registers the event notification infrastructure.
AddProjection<TProjection>(IEventSourcingBuilder, JsonTypeInfo<TProjection>, Action<IProjectionBuilder<TProjection>>)
Registers a projection using generated metadata and an AOT-safe store capability.
public static IEventSourcingBuilder AddProjection<TProjection>(this IEventSourcingBuilder builder, JsonTypeInfo<TProjection> typeInfo, Action<IProjectionBuilder<TProjection>> configure) where TProjection : class, new()
Parameters
builderIEventSourcingBuilderEvent sourcing builder.
typeInfoJsonTypeInfo<TProjection>The same generated metadata instance supplied by the store's JSON context.
configureAction<IProjectionBuilder<TProjection>>Projection handlers and processing mode.
Returns
- IEventSourcingBuilder
The builder.
Type Parameters
TProjectionProjection state type.
Remarks
Unsupported stores or decorators are rejected; this overload never falls back to reflective persistence.
AddProjection<TProjection, TConfig>(IEventSourcingBuilder)
Registers a projection using a DI-resolved IProjectionConfiguration<TProjection> implementation. The configuration class is resolved from the service provider at startup to configure the projection's mode, event handlers, and options.
[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 AddProjection<TProjection, TConfig>(this IEventSourcingBuilder builder) where TProjection : class, new() where TConfig : class, IProjectionConfiguration<TProjection>, new()
Parameters
builderIEventSourcingBuilderThe event sourcing builder.
Returns
- IEventSourcingBuilder
The builder for fluent chaining.
Type Parameters
TProjectionThe projection state type.
TConfigThe configuration type implementing IProjectionConfiguration<TProjection>. Must have a public parameterless constructor or be pre-registered in DI.
Examples
services.AddExcalibur(x => x.AddEventSourcing(builder =>
{
builder.AddProjection<OrderSummary, OrderSummaryProjectionConfig>();
}));
Remarks
This is the preferred registration path for projections when using the class-based configuration pattern. It avoids reflection-based assembly scanning while supporting DI-injected configuration classes.
A second call for the same projection type replaces the first.
AddProjectionsFromAssembly(IEventSourcingBuilder, Assembly)
Scans the specified assembly for types implementing IProjectionConfiguration<TProjection> and registers each discovered projection via AddProjection<TProjection>(IEventSourcingBuilder, Action<IProjectionBuilder<TProjection>>).
[RequiresUnreferencedCode("Assembly scanning uses reflection to discover IProjectionConfiguration<T> implementations.")]
[RequiresDynamicCode("Uses Activator.CreateInstance and MethodInfo.MakeGenericMethod for dynamic projection registration.")]
public static IEventSourcingBuilder AddProjectionsFromAssembly(this IEventSourcingBuilder builder, Assembly assembly)
Parameters
builderIEventSourcingBuilderThe event sourcing builder.
assemblyAssemblyThe assembly to scan for projection configurations.
Returns
- IEventSourcingBuilder
The builder for fluent chaining.
Examples
services.AddExcalibur(x => x.AddEventSourcing(builder =>
{
builder.AddProjectionsFromAssembly(typeof(OrderSummary).Assembly);
}));
Remarks
Assemblies with no IProjectionConfiguration<TProjection> implementations are handled gracefully (no-op).
UseEventNotification(IEventSourcingBuilder)
Registers the event notification broker and the projection registry. Called automatically by AddProjection<TProjection>(IEventSourcingBuilder, Action<IProjectionBuilder<TProjection>>).
public static IEventSourcingBuilder UseEventNotification(this IEventSourcingBuilder builder)
Parameters
builderIEventSourcingBuilderThe event sourcing builder.
Returns
- IEventSourcingBuilder
The builder for fluent chaining.
UseProjectionRecovery(IEventSourcingBuilder)
Registers the IProjectionRecovery service, which re-folds one aggregate's projection row from its event stream on demand.
public static IEventSourcingBuilder UseProjectionRecovery(this IEventSourcingBuilder builder)
Parameters
builderIEventSourcingBuilderThe event sourcing builder.
Returns
- IEventSourcingBuilder
The builder for fluent chaining.
Examples
services.AddExcalibur(x => x.AddEventSourcing(builder =>
{
builder.UseProjectionRecovery();
}));
Remarks
Called automatically by UseEventNotification(IEventSourcingBuilder). Consumers who only want recovery without full notification can call this directly.
WithProjectionHealthChecks(IEventSourcingBuilder)
Adds a health check for projections.
public static IEventSourcingBuilder WithProjectionHealthChecks(this IEventSourcingBuilder builder)
Parameters
builderIEventSourcingBuilderThe event sourcing builder.
Returns
- IEventSourcingBuilder
The builder for fluent chaining.
Examples
builder.Services.AddEventSourcing(es =>
{
es.AddProjection<OrderSummary>()
.WithProjectionHealthChecks();
});
Remarks
Registers a health check named "projections" that monitors projection lag
and error state. This is opt-in — projections work without health checks.
To customize thresholds, configure Excalibur.EventSourcing.Health.ProjectionHealthCheckOptions via the options pattern.