Repository navigation
v11.0.0 #1245
AndrewTriesToCode
announced in
Announcements
v11.0.0
#1245
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
MultiTenant v11.0.0
v11 is the biggest update to MultiTenant in a long time. Tenant IDs can now be any type you like, the current tenant comes from a new ambient tenant scope, and the stores are simpler. It's a major version, so there are breaking changes. The highlights and migration notes are below.
The big changes
New license for the official packages
The official NuGet packages are now licensed under the [Open Source Maintenance Fee EULA](https://github.com/Finbuckle/Finbuckle.MultiTenant/blob/main/OSMFEULA.txt). The source code stays Apache 2.0. If you use the packages as part of generating revenue, the maintenance fee applies. See [pricing](https://www.finbuckle.com/Pricing) for details, including free use for smaller organizations.
To accept the EULA, set the
AcceptFinbuckleEULAproperty in your project file orDirectory.Build.props:You can also pass
-p:AcceptFinbuckleEULA=trueon the command line. Until it's set, Release builds show warningFBMT0001, and builds that treat warnings as errors will fail.The packages and assemblies also now come with GitHub build provenance attestations, so you can check that what you installed was built from this repo.
Tenant IDs can be any type
ITenantInfois nowITenantInfo<TId>, so your tenant ID can be anint, aGuid, or any other equatable type, not just a string. Types and methods that took a tenant info type parameter now take aTIdparameter as well.default(TId)now means "no tenant", the waynulldid before.The current tenant comes from an ambient tenant scope
The old
IMultiTenantContextAccessor/IMultiTenantContextSetterpair is gone. InjectITenantContextto get the current tenant. Behind it, anITenantScopeProviderkeeps track of which tenant is current as your code flows throughasynccalls.UseMultiTenant<TId>()can still see the tenant. CallAddHttpAmbientTenantScope()(the ASP.NET Core builder helpers do this for you).IServiceProvider.RunInTenantScopeAsyncruns a delegate as a given tenant in its own DI scope. That's useful for background jobs, the generic host, or work for another tenant during a request, and your current tenant isn't affected.UseMultiTenantruns (for example withHttpContext.SetTenantInfo), that tenant is now kept and resolution is skipped.TenantManager and simpler stores
A new
TenantManageris the one place to look up, add and change tenants, including the starting tenants for the in-memory store. The resolver now has one primaryStoreplus optionalStoreCachesthat are checked in order. This replaces the old list of stores,DistributedCacheStoreandMultiTenantStoreWrapper. Store methods now take cancellation tokens, and those tokens are passed through to remote store HTTP calls.Immutable tenant types work everywhere
Tenant info types can now use
set,initor constructor-only properties. They don't need to inherit fromTenantInfo<TId>or be records.ConfigurationStoreuses the standard configuration binder, so constructor-bound types just work.EchoStoreandConfigurationStorealso have newtenantInfoFactoryoverloads for types the binder can't build..NET 11
v11 targets
net11.0only, with runtime async turned on.Safer Entity Framework Core
TenantIdtype doesn't match the context's tenant ID type, you get a clear error when the model is built, not aNullReferenceExceptionon the first query. Contexts that implementIMultiTenantDbContextthemselves can opt in withValidateMultiTenantIdType<TId>().DbContextand IdentityDbContextconstructors no longer take an accessor. They get the tenant from the ambient tenant scope. There are new registration helpers for tenant-aware and pooledDbContexts.IsMultiTenant: on entity types it is now a property instead of a method.Smaller improvements and fixes
ITenantScopeProviderisn't registered as a singleton, you now get a clear error at startup.HttpContextreuse.Upgrading from v10
<AcceptFinbuckleEULA>true</AcceptFinbuckleEULA>in your project file orDirectory.Build.props. Without it, Release builds show warningFBMT0001, and builds that treat warnings as errors will fail.TIdtype argument wherever you use your tenant info type, such asITenantInfo<string>.IMultiTenantContextAccessor/IMultiTenantContextwithITenantContext.ITenantScopeProviderneed the newEndScope()andHasScopemembers.InMemoryStoreOptionswithTenantManager. Replace multiple stores andDistributedCacheStorewith one store plus store caches.DbContextconstructors.WithStaticStrategyorWithDelegateStrategy, callAddHttpAmbientTenantScope()yourself.Thanks to everyone who reported issues and sent PRs for this release!
All reactions