Pragmatic.MultiTenancy.AspNetCore
1.0.0-alpha.6
dotnet add package Pragmatic.MultiTenancy.AspNetCore --version 1.0.0-alpha.6
NuGet\Install-Package Pragmatic.MultiTenancy.AspNetCore -Version 1.0.0-alpha.6
<PackageReference Include="Pragmatic.MultiTenancy.AspNetCore" Version="1.0.0-alpha.6" />
<PackageVersion Include="Pragmatic.MultiTenancy.AspNetCore" Version="1.0.0-alpha.6" />
<PackageReference Include="Pragmatic.MultiTenancy.AspNetCore" />
paket add Pragmatic.MultiTenancy.AspNetCore --version 1.0.0-alpha.6
#r "nuget: Pragmatic.MultiTenancy.AspNetCore, 1.0.0-alpha.6"
#:package Pragmatic.MultiTenancy.AspNetCore@1.0.0-alpha.6
#addin nuget:?package=Pragmatic.MultiTenancy.AspNetCore&version=1.0.0-alpha.6&prerelease
#tool nuget:?package=Pragmatic.MultiTenancy.AspNetCore&version=1.0.0-alpha.6&prerelease
Pragmatic.MultiTenancy
Shared-schema multi-tenancy for the Pragmatic.Design ecosystem: tenant resolution, scoping, and automatic query filtering: zero config for single-tenant apps, pluggable strategies for SaaS.
The Problem
Multi-tenant SaaS must isolate data per tenant. Without framework support, every query must filter by
tenant, every write must assign it, and every background job must propagate the tenant context. Miss
one WHERE TenantId = @current and you have a cross-tenant data leak, something code review catches
sometimes and tests catch never.
// Without Pragmatic: manual tenant filtering everywhere (easy to forget → data leak)
return await db.Invoices.Where(i => i.TenantId == currentTenantId).ToListAsync(ct);
Caching leaks too (invoices:latest returns the wrong tenant's data), and resolution varies (headers
in dev, JWT in prod, subdomains for some APIs).
The Solution
Mark entities ITenantEntity; the generator filters and assigns the tenant automatically, and an
AsyncLocal tenant context flows through async continuations (including background jobs).
[Entity]
public partial class Invoice : IEntity, ITenantEntity { /* TenantId set + filtered automatically */ }
// resolution strategy chosen once, in Program.cs
app.UseMultiTenancy(mt => mt.UseHeader()); // or UseClaim / UseSubdomain / UseRoute / UseResolver<T>
// UseDbPerTenant(...) for DB-per-tenant (Persistence package)
Security.
header/route/subdomainread the tenant from client-controlled input and are meant for pre-auth resolution. For authenticated requests the resolved tenant is validated against the user'stenant_idclaim (fail-closed, HTTP 403 on mismatch): an authenticated user cannot escalate to another tenant by spoofing the header/route/host. See tenant-resolution.md.
Installation
dotnet add package Pragmatic.MultiTenancy.AspNetCore # HTTP resolvers + UseMultiTenancy
dotnet add package Pragmatic.MultiTenancy.Persistence # optional: DB-per-tenant
| Package | Role |
|---|---|
Pragmatic.MultiTenancy |
Tenant context, scoping, configuration; no ASP.NET Core dependency |
Pragmatic.MultiTenancy.AspNetCore |
Header/claim/subdomain/route resolvers, the resolution middleware, UseMultiTenancy |
Pragmatic.MultiTenancy.Persistence |
DB-per-tenant: per-tenant connection strings, provisioning, migration orchestration |
ITenantEntity lives in Pragmatic.Abstractions, so a domain module marks its entities without
referencing any of these.
Status
Functional within 1.0.0-alpha: tenant resolution strategies, shared-schema filtering, database-per-tenant, and non-HTTP propagation. See the roadmap.
Documentation
| Guide | What you'll learn |
|---|---|
| Concepts | The tenancy model, ITenantEntity, ambient context, cache scoping |
| Getting Started | Mark entities, choose a resolver, wire the middleware |
| Tenant Resolution | Header/claim/subdomain/route/custom resolvers, ordering, non-HTTP contexts |
| Common Mistakes | The most frequent tenancy pitfalls |
| Troubleshooting | Problem/solution guide |
Requirements
- .NET 10.0+
License
Part of the Pragmatic.Design ecosystem. See Licensing. Pragmatic.MultiTenancy is licensed under the PolyForm Small Business 1.0.0 license (free for small businesses; commercial license above the threshold).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- Pragmatic.Composition (>= 1.0.0-alpha.6)
- Pragmatic.MultiTenancy (>= 1.0.0-alpha.6)
-
net11.0
- Pragmatic.Composition (>= 1.0.0-alpha.6)
- Pragmatic.MultiTenancy (>= 1.0.0-alpha.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Pragmatic.MultiTenancy.AspNetCore:
| Package | Downloads |
|---|---|
|
Pragmatic.MultiTenancy.Persistence
DB-per-tenant support for Pragmatic.Design. Provides tenant-aware connection string resolution, database provisioning, and migration orchestration. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.6 | 130 | 11/21/2026 |
| 1.0.0-alpha.5 | 58 | 11/21/2026 |
| 1.0.0-alpha.4 | 118 | 11/16/2026 |
| 1.0.0-alpha.3 | 513 | 10/17/2026 |
| 1.0.0-alpha.2 | 125 | 10/12/2026 |
| 1.0.0-alpha.1 | 346 | 10/3/2026 |