Configuration & Integrations — MultiTenancy
Configure HTTP tenant resolution middleware, per-tenant authentication cookies, and database session isolation.
TenantResolutionMiddlewareOptions & Middleware
Section titled “TenantResolutionMiddlewareOptions & Middleware”TenantResolutionMiddlewareOptions (in EricksonLopez.MultiTenancy.AspNetCore.Options) exposes:
RequireTenant(defaultfalse) — enforce tenant presence globally, or per-endpoint with.RequireTenant()/.AllowAnonymousTenant().FailOnStoreMiss(defaulttrue) — reject unknown tenant IDs instead of continuing anonymously.WriteProblemDetailsOnConflict(defaultfalse) — emit RFC 9457 ProblemDetails on claim vs strategy mismatch.ValidateAuthenticatedPrincipalTenantClaim(defaulttrue,TenantClaimType = "tenant_id") — prevent cross-tenant spoofing after authentication.
- PostgreSQL:
connection.BeginTenantTransactionAsync(...)andconnection.SetTenantRlsContextAsync(DbTransaction, ITenantContext, sessionVariable = "app.current_tenant_id"). - SQL Server (
BC-003):connection.SetTenantSessionContextAsync(DbTransaction transaction, ITenantContext tenantContext, string sessionKey = "TenantId", bool readOnly = false)(transactionis the mandatory 2nd parameter inv2.0.0). - Dapper:
parameters.WithTenant(tenantContext)andtenantContext.CreateTenantParameters(...). - Authentication & OpenTelemetry:
AddPerTenantAuthentication<TTenant>()andTenantActivitySource/TenantMetrics/TenantTraceEnricher.
Unpublished & Removed Notes:
EricksonLopez.MultiTenancy.Caching(AddTenantDistributedCache()) is local-only (3.1.0, unpublished on NuGet).EricksonLopez.MultiTenancy.EntityFrameworkCorewas removed inv1.0.0(BC-106).