Table of Contents

Class DefaultTenantContextServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Excalibur.Dispatch.Abstractions.dll

Registration helpers for the default ITenantContext.

public static class DefaultTenantContextServiceCollectionExtensions
Inheritance
DefaultTenantContextServiceCollectionExtensions
Inherited Members

Methods

AddDefaultTenantContext(IServiceCollection)

Registers the fail-closed single-tenant default ITenantContext if no context has been registered yet.

public static IServiceCollection AddDefaultTenantContext(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection.

Returns

IServiceCollection

The same services instance, for chaining.

Remarks

A store that scopes rows by tenant requires an ITenantContext. This provides the non-null single-tenant default so GetRequiredService<ITenantContext>() always resolves; the multi-tenancy composition replaces it with the ambient, resolver-driven context. Idempotent: uses TryAdd, so an already-registered context wins. Also wires a fail-closed startup guard (Excalibur.Dispatch.TenantContextConsistencyValidator) that rejects the silent cross-tenant loss configuration — a resolving ITenantContext registered while the deployment stays in single-tenant mode (RequireTenant false). The guard runs before the first message whenever a tenant-scoped store is registered.

AddTenantContextMode<TMode>(IServiceCollection)

Contributes a tenant-context mode. ITenantContext resolves to the contributed mode with the highest Precedence, whatever order modes were contributed in.

public static IServiceCollection AddTenantContextMode<TMode>(this IServiceCollection services) where TMode : class, ITenantContextMode

Parameters

services IServiceCollection

The service collection.

Returns

IServiceCollection

The same services instance, for chaining.

Type Parameters

TMode

The mode to contribute.

Remarks

Idempotent: contributing the same mode twice has the effect of contributing it once. The single-tenant default is always present, at precedence 0.

Two different modes with the same highest precedence are refused when the host starts, and on first resolution, naming both. A context registered directly as ITenantContext takes the place of every mode.