EricksonLopez.MultiTenancy Overview
EricksonLopez.MultiTenancy (2.0.0 on NuGet, L2) enforces tenant boundary propagation from HTTP resolution (TenantResolutionMiddleware) down to database row-level security (PostgreSQL SET LOCAL, SQL Server SESSION_CONTEXT, MySQL/MariaDB session variables, and Dapper parameter binding).
- Immutable
TenantId(ISpanParsable<TenantId>): Zero-allocation span parsing, UUIDv7NewId(), andResult<TenantId>validation (TenantId.From(...)). - Fail-closed database isolation:
PostgreSqlRlsExtensions(BeginTenantTransactionAsync,SetTenantRlsContextAsync) binds tenant context to transaction-scopedSET LOCAL, while Roslyn analyzers (ELMT001–ELMT004) flag Dapper queries missing tenant predicates or superuser connection strings. - Explicit authentication binding:
ValidateAuthenticatedPrincipalTenantClaim(trueby default) rejects spoofed headers/routes that conflict with authenticated"tenant_id"claims. - Accurate package scope:
15of16packages are published (2.0.0);EricksonLopez.MultiTenancy.Cachingis unpublished (3.1.0local only), andEntityFrameworkCorewas removed inv1.0.0(BC-106).
Rendering diagram…
flowchart LR HTTP["HTTP Request"] --> MW["TenantResolutionMiddleware (8 Strategies)"] MW --> Ctx["ITenantContext / ScopedTenantContextAccessor"] Ctx --> DB["PostgreSQL SET LOCAL / Dapper WithTenant"] Ctx -- Unresolved & RequireTenant --> Err["TenantErrors.Unresolved / 400-403"]
View accessible text summary and structure
TenantResolutionMiddleware resolves TenantId from host, route, header, or claim, populates ITenantContext, and propagates it into PostgreSQL RLS or Dapper parameterized queries.
flowchart LR
HTTP["HTTP Request"] --> MW["TenantResolutionMiddleware (8 Strategies)"]
MW --> Ctx["ITenantContext / ScopedTenantContextAccessor"]
Ctx --> DB["PostgreSQL SET LOCAL / Dapper WithTenant"]
Ctx -- Unresolved & RequireTenant --> Err["TenantErrors.Unresolved / 400-403"]Package Roster & Native AOT Status (15 / 16 Published)
Section titled “Package Roster & Native AOT Status (15 / 16 Published)”Overall AOT status is Partial (13 Full, 2 Incompatible, 1 NotApplicable). Note that EricksonLopez.MultiTenancy.Dapper is Full AOT, whereas Oracle and SqlServer are Incompatible:
| Package | NuGet (2.0.0) |
AOT Status | TFMs | Role |
|---|---|---|---|---|
EricksonLopez.MultiTenancy |
Published (347 dl) |
Full |
net8.0;net9.0;net10.0 |
ScopedTenantContextAccessor, DefaultTenantScopeFactory, InMemoryTenantStore<T>, CachedTenantStore<T> |
EricksonLopez.MultiTenancy.Abstractions |
Published (675 dl) |
Full |
net8.0;net9.0;net10.0 |
TenantId, TenantInfo, ITenantContext, TenantErrors, IOrganizationContext |
EricksonLopez.MultiTenancy.AspNetCore |
Published (308 dl) |
Full |
net8.0;net9.0;net10.0 |
TenantResolutionMiddleware, 8 strategies, RequireTenant(), AllowAnonymousTenant() |
EricksonLopez.MultiTenancy.Authentication |
Published (286 dl) |
Full |
net8.0;net9.0;net10.0 |
AddPerTenantAuthentication<TTenant>, TenantCookieAuthenticationEvents<TTenant> |
EricksonLopez.MultiTenancy.Configuration |
Published (301 dl) |
Full |
net8.0;net9.0;net10.0 |
ConfigurationTenantStore<TTenant> |
EricksonLopez.MultiTenancy.Dapper |
Published (285 dl) |
Full |
net8.0;net9.0;net10.0 |
WithTenant, CreateTenantParameters (Full AOT) |
EricksonLopez.MultiTenancy.PostgreSql |
Published (285 dl) |
Full |
net8.0;net9.0;net10.0 |
BeginTenantTransactionAsync, SetTenantRlsContextAsync, PostgreSqlTenantStore |
EricksonLopez.MultiTenancy.MariaDb / .MySql / .Sqlite |
Published (280/267/286 dl) |
Full |
net8.0;net9.0;net10.0 |
Dialect session variables and connection factories |
EricksonLopez.MultiTenancy.OpenTelemetry / .Testing |
Published (267/277 dl) |
Full |
net8.0;net9.0;net10.0 |
TenantActivitySource, TenantMetrics, FakeTenantStore, TestTenantContext |
EricksonLopez.MultiTenancy.Oracle / .SqlServer |
Published (282/284 dl) |
Incompatible |
net8.0;net9.0;net10.0 |
IsAotCompatible=false, EnableTrimAnalyzer=false (Oracle.ManagedDataAccess.Core / Microsoft.Data.SqlClient) |
EricksonLopez.MultiTenancy.Analyzers |
Published (255 dl) |
NotApplicable |
netstandard2.0 |
Roslyn rules ELMT001–ELMT004 |
EricksonLopez.MultiTenancy.Caching |
Unpublished | Full |
net8.0;net9.0;net10.0 |
Local workspace 3.1.0 only (TenantDistributedCacheDecorator) |
Benchmark Status:
hasBenchmarks: false— no BenchmarkDotNet reports are published fordotnet-multitenancy.