Mutlitenancy for dotnet applications
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

c# Dotnettency Mutlitenancy library for dotnet applications.

Branch Build Status
Master Build status
Develop Build status
Branch Dotnettency Core Library Middleware Container EF Core
Master Dotnettency MiddlewarePipeline Container EF Core
Develop Dotnettency MiddlewarePipeline Container EF Core
Branch Autofac StructureMap
Master Autofac StructureMap
Develop Autofac StructureMap

Inspired by saaskit



  • Tenant resolution
  • Per Tenant Middleware Pipeline
  • Per Tenant Containers
  • Per Tenant HostingEnvironment
  • Modules (Shared and Routed)
  • Multitenant EF Core DbContext

Tenant Injection

Once configured in startup.cs you can resolve the current tenant in any one of the following ways:

  • Inject TTenant directly (may block whilst resolving current tenant).
  • Inject Task<TTenant> - Allows you to await the current Tenant (so non blocking). Task<TTenant> is convenient.
  • Inject ITenantAccessor<TTenant>. This is similar to injecting Task<Tenant> in that it provides lazy access the current tenant in a non blocking way. For convenience it's now easier to just inject Task<Tenant> instead, unless you want a more descriptive API.

Tenant Shell Injection

The TenantShell stores additional context for a Tenant, such as it's Container and it's MiddlewarePipeline.

  • Inject ITenantShellAccessor<TTenant> in order to access context for the currnet tenant, which is primarily used by:
    • Extensions (such as Middleware, or Container) - which store things for the tenant in the ITenantShellAccessor<TTenant>'s concurrent property bag.
    • Tenant Admin screens - if you need to "Restart" a tenant, then the idea is, you can resolve the ITenantShellAccessor<TTenant> and then use extension methods (provided by the dotnettency extensions such as Middleware pipeline, or Container) to allow you to control the state of the running tenant - for example to trigger rebuild of the tenant's container, or pipeline on the next request.

Notes: For details on what Per Tenant Hosting Environment does see the README on the sample.