Finbuckle.MultiTenant
9.0.0
Prefix Reserved
dotnet add package Finbuckle.MultiTenant --version 9.0.0
NuGet\Install-Package Finbuckle.MultiTenant -Version 9.0.0
<PackageReference Include="Finbuckle.MultiTenant" Version="9.0.0" />
paket add Finbuckle.MultiTenant --version 9.0.0
#r "nuget: Finbuckle.MultiTenant, 9.0.0"
// Install Finbuckle.MultiTenant as a Cake Addin #addin nuget:?package=Finbuckle.MultiTenant&version=9.0.0 // Install Finbuckle.MultiTenant as a Cake Tool #tool nuget:?package=Finbuckle.MultiTenant&version=9.0.0
Finbuckle.MultiTenant <span class="_version">9.0.0</span>
About Finbuckle.MultiTenant
Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation. See https://www.finbuckle.com/multitenant for more details and documentation.
This release supports .NET 8 and .NET 9.
Current publish feed release:
Table of Contents
- What's New in v<span class="_version">9.0.0</span>
- Quick Start
- Documentation
- Sample Projects
- Build and Test Status
- License
- .NET Foundation
- Code of Conduct
- Community
- Building from Source
- Running Unit Tests
<a name="whats-new"></a> What's New in v<span class="_version">9.0.0</span>
This section only lists release update details specific to v<span class="_version">9.0.0</span>. See the changelog file for all release update details.
9.0.0 (2024-11-13)
Features
- add multitenant db factory method (#896) (8728447)
- better tenant resolution events (#897) (956ca36)
- dotnet 9 support (#893) (4be1b88)
- make builds deterministic and set latest GH actions (#889) (d82f89d)
BREAKING CHANGES
OnTenantResolved
andOnTenantNotResolved
are no longer used. Use theOnStrategyResolveCompleted
,OnStoreResolveCompleted
, andOnTenantResolveCompleted
events instead.MultiTenantDbContext
constructors accepting ITenantInfo removed, useMultiTenantDbContext.Create
factory methodMultiTenantDbContext
constructors accepting ITenantInfo removed, useMultiTenantDbContext .Create
factory method instead- net6.0 and net7.0 are no longer supported targets.
- dotnet runtime specific dependencies now float to the latest patch version and are locked at release time with a NuGet lock file. This is a security mitigation and may break some builds not on the latest SDKs.
Quick Start
Finbuckle.MultiTenant is designed to be easy to use and follows standard .NET conventions as much as possible. This introduction assumes a standard ASP.NET Core use case, but any application using .NET dependency injection can work with the library.
Installation
First, install the Finbuckle.MultiTenant.AspNetCore NuGet package:
.NET Core CLI
$ dotnet add package Finbuckle.MultiTenant.AspNetCore
Basic Configuration
Next, in the app's service configuration call AddMultiTenant<TTenantInfo>
and its various builder methods and in the
middleware configuration call UseMultiTenant()
:
builder.Services.AddMultiTenant<TenantInfo>()
.WithHostStrategy()
.WithConfigurationStore();
// other app code...
app.UseMultiTenant();
// other app code...
app.Run();
That's all that is needed to get going. Let's breakdown each line:
builder.Services.AddMultiTenant<TenantInfo>()
This line registers the base services and designates TenantInfo
as the class that will hold tenant information at
runtime.
The type parameter for AddMultiTenant<TTenantInfo>
must be an implementation of ITenantInfo
which holds basic
information about the tenant such as its name and an identifier. TenantInfo
is provided as a basic implementation, but
a custom implementation can be used if more properties are needed.
See Core Concepts for more information on ITenantInfo
.
.WithHostStrategy()
The line tells the app that our "strategy" to determine the request tenant will be to look at the request host, which defaults to the extracting the subdomain as a tenant identifier.
See MultiTenant Strategies for more information.
.WithConfigurationStore()
This line tells the app that information for all tenants are in the appsettings.json
file used for app configuration.
If a tenant in the store has the identifier found by the strategy, the tenant will be successfully resolved for the
current request.
See MultiTenant Stores for more information.
Finbuckle.MultiTenant comes with a collection of strategies and store types that can be mixed and matched in various ways.
app.UseMultiTenant()
This line configures the middleware which resolves the tenant using the registered strategies, stores, and other
settings. Be sure to call it before other middleware which will use per-tenant functionality,
e.g. UseAuthentication()
.
Basic Usage
With the services and middleware configured, access information for the current tenant from the TenantInfo
property on
the MultiTenantContext<T>
object accessed from the GetMultiTenantContext<T>
extension method:
var tenantInfo = HttpContext.GetMultiTenantContext<TenantInfo>().TenantInfo;
if(tenantInfo != null)
{
var tenantId = tenantInfo.Id;
var identifier = tenantInfo.Identifier;
var name = tenantInfo.Name;
}
The type of the TenantInfo
property depends on the type passed when calling AddMultiTenant<T>
during configuration.
If the current tenant could not be determined then TenantInfo
will be null.
The ITenantInfo
instance and/or the typed instance are also available directly through dependency injection.
See Configuration and Usage for more information.
Documentation
The library builds on this basic functionality to provide a variety of higher level features. See the documentation for more details:
- Per-tenant Options
- Per-tenant Authentication
- Entity Framework Core Data Isolation
- ASP.NET Core Identity Data Isolation
Sample Projects
A variety of sample projects are available in the repository. Check older tagged release commits for samples from prior .NET versions.
Build and Test Status
License
This project uses the Apache 2.0 license. See LICENSE file for license information.
.NET Foundation
This project is supported by the .NET Foundation.
Code of Conduct
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct or the CONTRIBUTING.md file.
Community
Check out the GitHub repository to ask a question, make a request, or peruse the code!
Building from Source
From the command line clone the git repository, cd
into the new directory, and compile with dotnet build
.
$ git clone https://github.com/Finbuckle/Finbuckle.MultiTenant.git
$ cd Finbuckle.MultiTenant
Cloning into 'Finbuckle.MultiTenant'...
<output omitted>
$ cd Finbuckle.MultiTenant
$ dotnet build
Running Unit Tests
Run the unit tests from the command line with dotnet test
from the solution directory.
$ dotnet test
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
-
net8.0
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Logging (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
-
net9.0
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Configuration (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.Http (>= 9.0.0)
- Microsoft.Extensions.Logging (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.0)
NuGet packages (26)
Showing the top 5 NuGet packages that depend on Finbuckle.MultiTenant:
Package | Downloads |
---|---|
Finbuckle.MultiTenant.AspNetCore
ASP.NET Core support for Finbuckle.MultiTenant. |
|
Finbuckle.MultiTenant.EntityFrameworkCore
Entity Framework Core support for Finbuckle.MultiTenant. |
|
Mcrio.Finbuckle.MultiTenant.RavenDb.Store
RavenDB implementations of the Finbuckle.MultiTenant store. |
|
fbognini.Application.Multitenancy
Package Description |
|
Finbuckle.MultiTenant.MongoFramework
Finbuckle.MultiTenant integration with MongoFramework providing tenant store and data isolation |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Finbuckle.MultiTenant:
Repository | Stars |
---|---|
fullstackhero/dotnet-starter-kit
Production Grade Cloud-Ready .NET 8 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.
|
|
enkodellc/blazorboilerplate
Blazor Boilerplate / Starter Template with MudBlazor
|
Version | Downloads | Last updated |
---|---|---|
9.0.0 | 6,091 | 11/13/2024 |
8.0.0 | 41,645 | 10/12/2024 |
7.0.2 | 77,237 | 8/3/2024 |
7.0.1 | 101,366 | 4/28/2024 |
7.0.0 | 7,217 | 4/21/2024 |
6.13.1 | 276,817 | 1/24/2024 |
6.13.0 | 71,990 | 12/21/2023 |
6.12.0 | 187,900 | 8/25/2023 |
6.11.1 | 60,013 | 7/6/2023 |
6.11.0 | 3,156 | 7/1/2023 |
6.10.0 | 652,570 | 1/30/2023 |
6.9.1 | 167,328 | 11/10/2022 |
6.9.0 | 68,577 | 10/23/2022 |
6.8.1 | 135,810 | 9/17/2022 |
6.8.0 | 60,839 | 8/28/2022 |
6.7.3 | 144,814 | 7/17/2022 |
6.7.2 | 226,566 | 4/5/2022 |
6.7.1 | 76,085 | 3/10/2022 |
6.7.0 | 4,389 | 3/6/2022 |
6.6.1 | 75,109 | 2/19/2022 |
6.6.0 | 12,078 | 2/13/2022 |
6.5.1 | 129,656 | 11/17/2021 |
6.5.0 | 10,168 | 11/8/2021 |