OswaldTechnologies.Multitenancy
2.0.1
dotnet add package OswaldTechnologies.Multitenancy --version 2.0.1
NuGet\Install-Package OswaldTechnologies.Multitenancy -Version 2.0.1
<PackageReference Include="OswaldTechnologies.Multitenancy" Version="2.0.1" />
paket add OswaldTechnologies.Multitenancy --version 2.0.1
#r "nuget: OswaldTechnologies.Multitenancy, 2.0.1"
// Install OswaldTechnologies.Multitenancy as a Cake Addin
#addin nuget:?package=OswaldTechnologies.Multitenancy&version=2.0.1
// Install OswaldTechnologies.Multitenancy as a Cake Tool
#tool nuget:?package=OswaldTechnologies.Multitenancy&version=2.0.1
ASP.NET Core Multitenancy
This library lets you add multitenancy to an ASP.Core application. You add its services to the DI container.
It adds a ITenantService
that provides two methods. GetCurrentTenant
fetches the current tenant configuration
based on the current hostname. GetTenantList
returns a list of all tenants in configuration. You are able to use
this service in other classes to change your database connection string.
How to use
Install the library.
Add the tenant configuration to appsettings.json
.
{
"Tenants": [
{
"Name": "Localhost Tenant",
"Hostname": "localhost:44331",
"ConnectionString": "conn1"
},
{
"Name": "Test Tenant",
"Hostname": "test.example.com",
"ConnectionString": "conn2"
}
]
}
Add the Multitenancy services to the dependency injection container.
using Multitenancy;
public void ConfigureServices(IServiceCollection services)
{
services.AddMultitenancy();
}
Inject into DbContext
to specify the database connection string for the current tenant.
public class ExampleContext : DbContext
{
private readonly ITenantService _tenantService;
public ExampleContext(DbContextOptions<ExampleContext> options, ITenantService tenantService)
: base(options)
{
_tenantService = tenantService;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(_tenantService.GetCurrentTenant().ConnectionString);
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.