Skip to main content
Table of Contents

Class ProjectionServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Stratara.Projections.dll

Dependency-injection extension methods that wire the Stratara projection runtime (manager, handler, method invoker, worker, replay worker) and discover IProjection implementations by assembly scan.

public static class ProjectionServiceCollectionExtensions
Inheritance
ProjectionServiceCollectionExtensions
Inherited Members

Methods

AddProjectionHandling(IServiceCollection, IConfiguration)

Registers the projection runtime without the worker that consumes the event-bundle subscription — Stratara.Projections.Services.ProjectionManager, Stratara.Projections.Services.ProjectionHandler, Stratara.Projections.Services.ProjectionMethodInvoker and the Stratara.Projections.Services.ProjectionReplayWorker, so a full replay still runs — and binds ProjectionOptions from the Projections section. For a host whose projections are fed by something other than the bus, such as the Orleans execution model's store readers. Calling it more than once registers each service once.

public static IServiceCollection AddProjectionHandling(this IServiceCollection services, IConfiguration configuration)

Parameters

services IServiceCollection

The service collection to register against.

configuration IConfiguration

The configuration root used to bind ProjectionOptions.

Returns

IServiceCollection

The service collection for chaining.

Examples

services.AddProjectionsFromAssemblyContaining<AccountBalanceProjection>();
services.AddProjectionHandling(configuration);

AddProjectionWorker(IServiceCollection, IConfiguration)

Registers the projection runtime — Stratara.Projections.Services.ProjectionManager, Stratara.Projections.Services.ProjectionHandler, Stratara.Projections.Services.ProjectionMethodInvoker, Stratara.Projections.Services.ProjectionWorker, and Stratara.Projections.Services.ProjectionReplayWorker — and binds ProjectionOptions from configuration. Everything AddProjectionHandling(IServiceCollection, IConfiguration) registers, plus the worker that consumes the event-bundle subscription.

public static IServiceCollection AddProjectionWorker(this IServiceCollection services, IConfiguration configuration)

Parameters

services IServiceCollection

The service collection to register against.

configuration IConfiguration

The configuration root used to bind ProjectionOptions.

Returns

IServiceCollection

The service collection for chaining.

Examples

Binds ProjectionOptions from the Projections section. Register the projections themselves separately — this call wires the runtime, not your read models:

services.AddProjectionsFromAssemblyContaining<AccountBalanceProjection>();
services.AddProjectionWorker(configuration);

AddProjectionsFromAssemblyContaining<T>(IServiceCollection)

Scans the assembly containing T and registers every concrete IProjection implementation it finds as a scoped service.

public static IServiceCollection AddProjectionsFromAssemblyContaining<T>(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection to register against.

Returns

IServiceCollection

The service collection for chaining.

Type Parameters

T

A marker type that lives in the assembly to scan (typically a per-project IMarker interface).

Examples

Discover and register every IProjection in the projections assembly:

public interface IProjectionsMarker { }

builder.Services.AddProjectionsFromAssemblyContaining<IProjectionsMarker>();

Remarks

Every payload type a HandleAsync takes is added to the trusted types. For a projection that declares IForgetsDeletedTenants, TenantDeleted and CustomerTenantsDeleted are added as well, because the projection is handed them whether or not it handles them.

Exceptions

InvalidOperationException

The host was already built from services, which is read-only: the types the running host trusts would change under it.