Announcing MultiTenant 11
Generic tenant IDs, an ambient tenant scope, TenantManager, safer EF Core data isolation, and a sustainable future for the project.
Note
This is part 1 of a 7-part series:
- Announcing MultiTenant 11 · This post
- Keeping MultiTenant Sustainable with the Open Source Maintenance Fee · Coming soon
- Generic Tenant IDs · Coming soon
- The Ambient Tenant Scope · Coming soon
- TenantManager and Store Caches · Coming soon
- Safer EF Core Data Isolation · Coming soon
- Supply Chain Integrity · Coming soon
MultiTenant 11 is the biggest update in years, and it's available now on NuGet. It reworks how the current tenant flows through an app, lets tenant IDs be more than strings, simplifies tenant storage, and makes EF Core data isolation stricter by default. It's also the first release under the Open Source Maintenance Fee. Here's a quick tour. The rest of the series covers each topic in depth.
Sustainability and the Open Source Maintenance Fee
The official NuGet packages are now licensed under the Open Source Maintenance Fee EULA. The source code stays Apache 2.0, and nothing is held back for a paid edition. Organizations that use the official packages to generate revenue pay a small maintenance fee, and it's free for anyone under $1M in annual revenue. See Pricing for the tiers.
To accept the EULA, set <AcceptFinbuckleEULA>true</AcceptFinbuckleEULA> in your project file or
Directory.Build.props. Until you do, Release builds show warning FBMT0001.
The next post explains why we chose this model and how the fee is set up.
.NET 11
MultiTenant 11 targets net11.0 only and has runtime async enabled. If you need to stay on .NET 10, keep using the MultiTenant 10 release
line.
Generic Tenant IDs
ITenantInfo is now ITenantInfo<TId>, so a tenant's Id can be a Guid, an int, or any IEquatable<TId> type.
EF Core TenantId columns use the same type, so they can be real foreign keys to your tenants table:
builder.Services.AddMultiTenant<AppTenantInfo, Guid>()
.WithHostStrategy()
.WithEFCoreStore<TenantStoreDbContext, AppTenantInfo, Guid>();
A later post covers the new default(TId) rule for "no tenant" and tenant types that can't be changed after creation.
The Ambient Tenant Scope
IMultiTenantContextAccessor and IMultiTenantContextSetter are gone. In their place is one ambient
ITenantContext<TTenantInfo, TId> that you can inject anywhere, and an explicit tenant scope that defines how long the
current tenant lasts. Within a scope the tenant can only be set once, so nothing can quietly switch tenants partway
through a request. ASP.NET Core begins a scope for every request automatically, and a new helper runs any code as a
specific tenant:
await services.RunInTenantScopeAsync(tenant, async scoped =>
{
var db = scoped.GetRequiredService<AppDbContext>();
await db.Database.ExecuteSqlRawAsync("...");
});
A later post covers scopes in ASP.NET Core, background services, and jobs that run for every tenant.
TenantManager and Store Caches
Tenant storage now has one primary store, any number of read-through store caches in front of it, and a new
TenantManager<TTenantInfo, TId> that coordinates them. Reads check the caches first. Writes go to the store and then
invalidate the affected cache entries, so updating a tenant no longer leaves stale data in Redis or memory. A later post
covers the new API and the store changes.
Safer EF Core Data Isolation
The EF Core tenant query filter now fails closed: a DbContext with no tenant returns no rows instead of throwing. A
typed IsMultiTenant<TEntity, TId>() overload builds its filter without reflection, and a mismatched tenant ID type is
caught when the model is built rather than on some later query. A later post covers all of the EF Core changes.
Supply Chain Integrity
Every official .nupkg, .snupkg, and library assembly now has a GitHub
artifact attestation that proves it was
built from the Finbuckle.MultiTenant repository by the official publishing workflow. You can check any of them with
gh attestation verify. See Verifying Packages for details. Starting with
11.0.1, the packages and their assemblies will also be code signed. A later post covers attestations, code signing,
trusted publishing, and the rest of the release pipeline.
Upgrading
MultiTenant 11 is a major version with breaking changes. Most upgrades come down to adding the tenant ID type to generic calls,
replacing the context accessor with ITenantContext, and using TenantManager instead of the store directly. The
MultiTenant 11.0.0 release discussion has the full migration
notes.
Thank You
Thank you to everyone who contributed code, reported an issue, or shared ideas and feedback in GitHub issues and discussions. Many of MultiTenant 11's changes started there: