Pavas.Runtime.TenantContext
1.0.0
dotnet add package Pavas.Runtime.TenantContext --version 1.0.0
NuGet\Install-Package Pavas.Runtime.TenantContext -Version 1.0.0
<PackageReference Include="Pavas.Runtime.TenantContext" Version="1.0.0" />
paket add Pavas.Runtime.TenantContext --version 1.0.0
#r "nuget: Pavas.Runtime.TenantContext, 1.0.0"
// Install Pavas.Runtime.TenantContext as a Cake Addin #addin nuget:?package=Pavas.Runtime.TenantContext&version=1.0.0 // Install Pavas.Runtime.TenantContext as a Cake Tool #tool nuget:?package=Pavas.Runtime.TenantContext&version=1.0.0
Pavas.Runtime.TenantContext
Pavas.Runtime.TenantContext is a library designed to manage multi-tenancy in applications, allowing for dynamic tenant selection based on request headers or default tenant configurations. This is particularly useful in environments where the same application serves multiple clients (tenants) and needs to differentiate between them based on the incoming request.
Features
- Multi-Tenant Support: Manage multiple tenants with ease by specifying a list of tenants and selecting the
appropriate one based on the
X-Tenant-ID
header or a default setting. - Dynamic Tenant Resolution: The tenant can be dynamically resolved from the incoming request header
X-Tenant-ID
. If the header is not provided, the system will use the default tenant as defined in the configuration. - Centralized Configuration: The tenants are configured centrally, making it easy to manage and update tenant information.
Installation
To use this library, include it in your project and configure the tenant context as part of your service configuration.
Usage
Configuring Tenants
Define a list of tenants and set one as the default:
List<Tenant> tenants = [ new Tenant { Id = "Develop", Name = "Develop", Connection = "MyConnectionDevelop", IsDefault = true }, new Tenant { Id = "ProductionTenant", Name = "ProductionTenant", Connection = "MyConnectionToProduction" }, new Tenant { Id = "TestTenant", Name = "TestTenant", Connection = "MyConnectionToTest" } ];
Inject the tenant context during the application service configuration:
builder.Services.AddTenantContext(tenants);
Use the TenantContext middleware to enable tenants in your application:
app.UseTenantContextMiddleware();
Handling Tenant Resolution
- Header-Based Resolution: The tenant is resolved based on the
X-Tenant-ID
header included in the HTTP request. This allows the application to dynamically switch between tenants depending on the incoming request. - Default Tenant: If the
X-Tenant-ID
header is not provided, the application will fall back to the tenant marked asIsDefault
in the tenant configuration list.
Contribution
This is an ongoing project. If you wish to contribute, please fork the repository, create a new branch, and submit a pull request.
License
This project is licensed under the MIT License.
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. |
-
net8.0
- Microsoft.AspNetCore.Http (>= 2.1.34)
- Pavas.Patterns.Context (>= 1.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 116 | 8/25/2024 |