Table of Contents

Class TenantShardingServiceCollectionExtensions

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

Extension methods for configuring tenant-aware data sharding on IEventSourcingBuilder.

public static class TenantShardingServiceCollectionExtensions
Inheritance
TenantShardingServiceCollectionExtensions
Inherited Members

Methods

EnableTenantSharding(IEventSourcingBuilder, IConfiguration)

Enables tenant-aware data sharding for event stores and projection stores, with options bound from an IConfiguration section.

[UnconditionalSuppressMessage("AOT", "IL2026:RequiresUnreferencedCode", Justification = "Options validation/binding uses reflection by design. AOT consumers should use source-generated alternatives.")]
[UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode", Justification = "Configuration binding uses reflection by design. AOT consumers should use source-generated alternatives.")]
public static IEventSourcingBuilder EnableTenantSharding(this IEventSourcingBuilder builder, IConfiguration configuration)

Parameters

builder IEventSourcingBuilder

The event sourcing builder.

configuration IConfiguration

The configuration section to bind ShardMapOptions from.

Returns

IEventSourcingBuilder

The builder for fluent chaining.

Examples

services.AddExcalibur(x => x.AddEventSourcing(builder =>
{
    builder.EnableTenantSharding(configuration.GetSection("TenantSharding"));
}));

Remarks

Calling this method is the opt-in: sharding is always enabled when the extension is invoked. To avoid registering the tenant-routing decorator, do not call this method.

Registration semantics: calling this method replaces any previously registered IEventStore with Excalibur.EventSourcing.Sharding.TenantRoutingEventStore. Tenant routing is a whole-cloth replacement (not a wrapping decorator) because Excalibur.EventSourcing.Sharding.TenantRoutingEventStore resolves the correct store per tenant via ITenantStoreResolver<TStore>. If your host needs a single-tenant IEventStore alongside sharding, do not call this method — use provider-specific extensions directly.

EnableTenantSharding(IEventSourcingBuilder, Action<ShardMapOptions>)

Enables tenant-aware data sharding for event stores and projection stores.

public static IEventSourcingBuilder EnableTenantSharding(this IEventSourcingBuilder builder, Action<ShardMapOptions> configure)

Parameters

builder IEventSourcingBuilder

The event sourcing builder.

configure Action<ShardMapOptions>

Action to configure shard map options.

Returns

IEventSourcingBuilder

The builder for fluent chaining.

Examples

services.AddExcalibur(x => x.AddEventSourcing(builder =>
{
    builder.EnableTenantSharding(options =>
    {
        options.DefaultShardId = "shard-default";
    });
}));

Remarks

When enabled, IEventStore and IProjectionStore<TProjection> are re-registered as Scoped services that route to the correct shard based on the current tenant (via ITenantContext).

Consumers must also register an ITenantShardMap implementation (e.g., InMemoryTenantShardMap) and provider-specific ITenantStoreResolver<TStore> implementations.

Registration semantics: calling this method replaces any previously registered IEventStore with Excalibur.EventSourcing.Sharding.TenantRoutingEventStore. Tenant routing is a whole-cloth replacement (not a wrapping decorator) because Excalibur.EventSourcing.Sharding.TenantRoutingEventStore resolves the correct store per tenant via ITenantStoreResolver<TStore>. If your host needs a single-tenant IEventStore alongside sharding, do not call this method — use provider-specific extensions directly.