MultiTenancy.Core
0.0.8
See the version list below for details.
dotnet add package MultiTenancy.Core --version 0.0.8
NuGet\Install-Package MultiTenancy.Core -Version 0.0.8
<PackageReference Include="MultiTenancy.Core" Version="0.0.8" />
paket add MultiTenancy.Core --version 0.0.8
#r "nuget: MultiTenancy.Core, 0.0.8"
// Install MultiTenancy.Core as a Cake Addin
#addin nuget:?package=MultiTenancy.Core&version=0.0.8
// Install MultiTenancy.Core as a Cake Tool
#tool nuget:?package=MultiTenancy.Core&version=0.0.8
MultiTenancy
a lightway package to manage and implement multi tenant architecture to your .NET Core Applications
Usage
Usage in Startup
public void ConfigureServices(IServiceCollection services)
{
services.AddMultiTenancy<TenantCatalog, Guid>()
.AddTenantCatalogContext<TenantCatalogContext>(builder => builder.UseSqlServer("<Your connection string>"))
.AddTenantContext<TenantObjectContext>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Creates middleware that search for tenant-id in Header for each request and set it's to TenantProvider
app.UseMultiTenancy<TenantCatalog, Guid>();
// Use this if you want to migrate all tenants databases specified in Catalog Database
app.MigrateTenantDatabases<TenantCatalog, Guid>();
}
Create Tenant Catalog object context
public class ExampleTenantCatalogDbContext : TenantCatalogDbContext<TenantCatalog, Guid>
{
public ExampleTenantCatalogDbContext(DbContextOptions<ExampleTenantCatalogDbContext> options) : base(options)
{
}
}
Create tenant Object Context
We need to create our context that will be used across the application for retrivng and inserting data for various clients.
⚠️ It's important to implement DbContext with two constructors - One is for migrations and second is for using the application
public class TenantObjectContext : TenantDbContext<TenantCatalog, Guid>
{
public TenantObjectContext(ITenantProvider<TenantObject, Guid> provider,
DbContextOptions<TenantObjectContext> options) : base(provider, options)
{
}
public TenantObjectContext(
SqlConnectionStringBuilder connectionStringBuilder,
ITenantProvider<TenantObject, Guid> provider)
: base(connectionStringBuilder, provider)
{
}
}
Create tenant catalog object
public class TenantCatalog : Tenant<Guid>
{
}
Create tenant object
public class TenantObject : Tenancy<Guid>
{
}
Database Connection Support
Name | Supported |
---|---|
SqlServer | ✔ |
PostgreSQL | ❌ |
MySQL | ❌ |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.EntityFrameworkCore (>= 5.0.5)
- Microsoft.EntityFrameworkCore.InMemory (>= 5.0.5)
- Microsoft.EntityFrameworkCore.SqlServer (>= 5.0.5)
- Microsoft.Extensions.DependencyInjection (>= 5.0.1)
- System.Data.SqlClient (>= 4.8.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MultiTenancy.Core:
Package | Downloads |
---|---|
MultiTenancy.Core.InMemory
EF Core InMemory Database Provider for MT.Core |
|
MultiTenancy.Core.SqlServer
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
- Now every method has a comment !
- Added validation on adding tenant into database