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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pavas.Runtime.TenantContext" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pavas.Runtime.TenantContext --version 1.0.0                
#r "nuget: Pavas.Runtime.TenantContext, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

  1. 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"
        }
    ];
    
  2. Inject the tenant context during the application service configuration:

    builder.Services.AddTenantContext(tenants);
    
  3. 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 as IsDefault 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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