Skip to main content
Table of Contents

Class WorkerDefaultsHostBuilderExtensions

Namespace
Microsoft.Extensions.Hosting
Assembly
Stratara.EventSourcing.WorkerDefaults.dll

Worker-defaults composites that wire the Stratara event-sourced stack into a host with a single call. Each method chains together the per-concern DI extensions (mediator, write store, event sourcing, outbox, projections, sagas, identity, session, messaging, resilience) appropriate for one host shape.

public static class WorkerDefaultsHostBuilderExtensions
Inheritance
WorkerDefaultsHostBuilderExtensions
Inherited Members

Methods

AddBackendServices(IHostApplicationBuilder)

Registers the API-host stack: common framework services (messaging, identity, session, security, mapping, resilience) + mediator + write store + outbox dispatcher. For hosts that dispatch commands via the outbox but do not process them.

public static IHostApplicationBuilder AddBackendServices(this IHostApplicationBuilder builder)

Parameters

builder IHostApplicationBuilder

The host application builder.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Compose an API host that enqueues commands via the outbox without running handlers in-process:

var builder = WebApplication.CreateBuilder(args);
builder.AddBackendServices();
builder.Services
    .AddQueryHandlersFromAssemblyContaining<IAppMarker>();

var app = builder.Build();
app.MapPost("/orders", (PlaceOrder cmd, ICommandOutboxDispatcher d, CancellationToken ct) =>
    d.EnqueueCommandAsync(cmd, ct));
app.Run();

AddCommandWorkerServices(IHostApplicationBuilder)

Registers the command-worker stack: common framework services + mediator + mediator-worker (hosted service that consumes the command topic into the in-process mediator) + write store + event sourcing

  • outbox dispatcher.
public static IHostApplicationBuilder AddCommandWorkerServices(this IHostApplicationBuilder builder)

Parameters

builder IHostApplicationBuilder

The host application builder.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Compose a worker host that processes commands enqueued by API hosts:

var builder = Host.CreateApplicationBuilder(args);
builder.AddCommandWorkerServices();
builder.Services.AddCommandHandlersFromAssemblyContaining<IAppMarker>();
builder.Build().Run();

AddCommonFrameworkServices(IHostApplicationBuilder)

Wires the cross-cutting Stratara framework services that every worker host depends on — messaging, identity, session context, security, event-mapping, and resilience pipelines.

public static IHostApplicationBuilder AddCommonFrameworkServices(this IHostApplicationBuilder builder)

Parameters

builder IHostApplicationBuilder

The host application builder.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Bootstrap a custom worker shape that the documented Add*WorkerServices composites don't cover. Add only the framework primitives the host actually needs on top:

var builder = Host.CreateApplicationBuilder(args);
builder.AddCommonFrameworkServices();
builder.Services
    .AddWriteStore(builder.Configuration)
    .AddEventSourcing();
builder.Build().Run();

Remarks

Called internally by every Add*WorkerServices composite extension. Consumer hosts can also call it directly when they compose their own worker layout outside the documented composites.

AddEventProjectionWorkerServices(IHostApplicationBuilder)

Registers the event-projection-worker stack: common framework services + write store + projection replay state + projection worker (hosted service).

public static IHostApplicationBuilder AddEventProjectionWorkerServices(this IHostApplicationBuilder builder)

Parameters

builder IHostApplicationBuilder

The host application builder.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Compose a projection-worker host that fans event bundles out to read-model projections:

var builder = Host.CreateApplicationBuilder(args);
builder.AddEventProjectionWorkerServices();
builder.Services.AddProjectionsFromAssemblyContaining<IAppMarker>();
builder.Build().Run();

AddEventStreamHashWorkerServices(IHostApplicationBuilder)

Registers the event-stream-hash-worker stack: common framework services + write store + event-stream-hashing worker.

public static IHostApplicationBuilder AddEventStreamHashWorkerServices(this IHostApplicationBuilder builder)

Parameters

builder IHostApplicationBuilder

The host application builder.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Compose a worker host that continuously hashes event-streams to detect tampering:

var builder = Host.CreateApplicationBuilder(args);
builder.AddEventStreamHashWorkerServices();
builder.Build().Run();

AddHeavyCommandWorkerServices(IHostApplicationBuilder, int?)

Registers the heavy-command-worker stack: the same full command-handling stack as AddCommandWorkerServices(IHostApplicationBuilder) but with a dedicated heavy-command lane instead of the interactive one. Use it in a separate, independently scaled host that drains commands marked IHeavyCommand so long-running work never starves the interactive command lane.

public static IHostApplicationBuilder AddHeavyCommandWorkerServices(this IHostApplicationBuilder builder, int? degreeOfParallelism = null)

Parameters

builder IHostApplicationBuilder

The host application builder.

degreeOfParallelism int?

Concurrent subscriptions the heavy lane opens; null defaults to ProcessorCount. Cap it low to bound heavy-command resource use.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Compose a dedicated heavy-command worker host that drains IHeavyCommand commands at a bounded concurrency, leaving interactive command hosts unaffected:

var builder = Host.CreateApplicationBuilder(args);
builder.AddHeavyCommandWorkerServices(degreeOfParallelism: 2);
builder.Services.AddCommandHandlersFromAssemblyContaining<IAppMarker>();
builder.Build().Run();

AddOutboxWorkerServices(IHostApplicationBuilder)

Registers the outbox-worker stack: common framework services + write store + outbox dispatcher + outbox-retry worker. Use in a dedicated host that owns outbox-row retries; other hosts get the dispatcher via AddBackendServices(IHostApplicationBuilder) / AddCommandWorkerServices(IHostApplicationBuilder).

public static IHostApplicationBuilder AddOutboxWorkerServices(this IHostApplicationBuilder builder)

Parameters

builder IHostApplicationBuilder

The host application builder.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Compose a dedicated outbox-retry host:

var builder = Host.CreateApplicationBuilder(args);
builder.AddOutboxWorkerServices();
builder.Build().Run();

AddSagaWorkerServices(IHostApplicationBuilder)

Registers the saga-worker stack: common framework services + write store + event sourcing + outbox dispatcher + saga worker (hosted service that reacts to event bundles).

public static IHostApplicationBuilder AddSagaWorkerServices(this IHostApplicationBuilder builder)

Parameters

builder IHostApplicationBuilder

The host application builder.

Returns

IHostApplicationBuilder

The same builder for chaining.

Examples

Compose a saga-worker host that orchestrates long-running workflows triggered by domain events:

var builder = Host.CreateApplicationBuilder(args);
builder.AddSagaWorkerServices();
builder.Services.AddSagasFromAssemblyContaining<IAppMarker>();
builder.Build().Run();