- Shared services
- Per-tenant services
- Schema per-tenant (Data Isolation)
- Database per-tenant (Data Isolation)
- Shared database (Data Isolation)
- Shared options
- Per-tenant options
- Shared Authentication and Authorization
- Per-tenant Authentication and Authorization
- Add dependency to CodEaisy.TinySaas from Nuget
dotnet add package CodEaisy.TinySaas.AspNetCore --version 1.0.0
-
In
Startup.cs
, add the following inside theConfigureServices
method.public void ConfigureServices(IServiceCollection services) { // register all global singleton services here, and also dependencies for your TenantStore and ResolutionStrategy if any // ... // OPTION 1 services.AddMultitenancy<Tenant, TenantStore<Tenant>, TenantResolutionStrategy>(); // OPTION 2 // uses default `CodEaisy.TinySaas.Model.TinyTenant` as tenant model services.AddMultitenancy<TenantStore<TinyTenant>, TenantResolutionStrategy>(); // ... // services.AddControllers(); }
Then, add the following in the
Configure
methodpublic void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // enable multitenant support, with missing tenant handler and tenant container // OPTION 1 // missing tenant handler has a dependency that can be provided immediately app.UseMultitenancy<Tenant, MissingTenantHandler, MissingTenantOptions>(missingTenantOptions); // OPTION 2 // missing tenant handler does not have a dependency or dependency is already registered in services app.UseMultitenancy<Tenant, MissingTenantHandler>(); // OPTION 3 // Use `SimpleTenant` as tenant model, and missing tenant handler does not have a dependency or dependency is already registered in services app.UseMultitenancy<TMissingTenantHandler>() // ... }
-
In
Program.cs
, add the following in theCreateHostBuilder
method.public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }) // OPTION 1: add multitenant support via TenantStartup class .ConfigureMultitenancy<TenantStartup, Tenant>(); // OPTION 2: add multitenant support via static method .ConfigureMultitenancy<Tenant>(ClassName.StaticMethodName);
NOTE:
Tenant
must implementCodEaisy.TinySaas.Interface
ITenant
.TenantStore
must implementCodEaisy.TinySaas.Interface.ITenantStore
.TenantResolutionStrategy
must implementCodEaisy.TinySaas.Interface.ITenantResolutionStrategy
respectively.TenantStartup
must implementIMultitenantStartup
ClassName.StaticMethodName
must be of typeSystem.Action<TTenant, Autofac.ContainerBuilder>
whereTTenant
implementsITenant
Here, we show the performance report of an application singleton in a default ASP.NET application and an application singleton in a TinySaas ASP.NET application.
BenchmarkDotNet=v0.13.1, OS=macOS Big Sur 11.5.2 (20G95) [Darwin 20.6.0]
Intel Core i9-9880H CPU 2.30GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK=5.0.400
[Host] : .NET Core 3.1.5 (CoreCLR 4.700.20.26901, CoreFX 4.700.20.27001), X64 RyuJIT
.NET 5.0 : .NET 5.0.9 (5.0.921.35908), X64 RyuJIT
.NET Core 3.1 : .NET Core 3.1.5 (CoreCLR 4.700.20.26901, CoreFX 4.700.20.27001), X64 RyuJIT
Method | Job | Runtime | Instance | Mean | Error | StdDev | Ratio | RatioSD |
---|---|---|---|---|---|---|---|---|
HttpGet | .NET 5.0 | .NET 5.0 | Default | 43.95 μs | 0.791 μs | 1.598 μs | 0.90 | 0.04 |
HttpGet | .NET Core 3.1 | .NET Core 3.1 | Default | 50.06 μs | 0.979 μs | 1.088 μs | 1.00 | 0.00 |
HttpGet | .NET 5.0 | .NET 5.0 | TinySaas | 64.24 μs | 0.291 μs | 0.272 μs | 0.92 | 0.03 |
HttpGet | .NET Core 3.1 | .NET Core 3.1 | TinySaas | 69.96 μs | 1.389 μs | 1.993 μs | 1.00 | 0.00 |
Method | Job | Runtime | Instance | Mean | Error | StdDev | Ratio | RatioSD |
---|---|---|---|---|---|---|---|---|
HttpGet | .NET 5.0 | .NET 5.0 | TinySaas | 64.89 μs | 0.237 μs | 0.185 μs | 0.88 | 0.02 |
HttpGet | .NET Core 3.1 | .NET Core 3.1 | TinySaas | 74.95 μs | 1.437 μs | 1.869 μs | 1.00 | 0.00 |
ASP.NET Core 3.1+
Learn about the latest improvements.
Gunnar Peipman and Michael McKenna for their awesome works on Saas in ASP.NET Core.
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues in the hotlist: community-help.