Skip to content

Multi-tenancy ​

Ayaka.MultiTenancy answers one question for every piece of work in a .NET application: which tenant is this for? A tenant might be a customer organization, a workspace, or an account. Ayaka carries the tenant's identity through an execution flow, keeps a catalog of known tenants, and selects the tenant for each ASP.NET Core request.

Preview

The multi-tenancy packages are in preview. Their API can change between releases; check the release notes when you update.

How the pieces fit together ​

Outside HTTP requests (background jobs, message handlers), your code sets the tenant context itself; see Background work.

ComponentWhat it doesRead more
Tenant contextHolds the current tenant for the running execution flow.Tenant context
Tenant managementAdds, updates, removes, and looks up known tenants in a store.Managing tenants
Tenant cachingKeeps tenant lookups in memory so requests do not hit the store every time.Caching
Request pipelineMiddleware that sets the tenant context for each ASP.NET Core request.Request pipeline
Tenant detectionReads a tenant ID from a header, the host, or your own source.Tenant detection
Tenant resolutionTurns a detected ID into a tenant context, optionally rejecting unknown tenants.Tenant resolution

Choose your packages ​

PackageUse it for
Ayaka.MultiTenancy.AbstractionsContracts and models, for libraries that should not choose an implementation.
Ayaka.MultiTenancyThe tenant context accessor, tenant management, the in-memory store, and HybridCache integration.
Ayaka.MultiTenancy.AspNetCoreRequest detection, context resolution, and middleware for ASP.NET Core.

For a web application, install Ayaka.MultiTenancy and Ayaka.MultiTenancy.AspNetCore; a worker service needs only Ayaka.MultiTenancy. Both require ILoggerFactory, which ASP.NET Core and the Generic Host register for you.

NamespaceContains
Ayaka.MultiTenancyTenantContext, ITenantContextAccessor, AddMultiTenancy()
Ayaka.MultiTenancy.ManagementTenant, ITenantManager, ITenantStore, ITenantCache
Ayaka.MultiTenancy.DependencyInjectionBuilder interfaces and their registration extensions, UseMultiTenancy()
Ayaka.MultiTenancy.AspNetCoreRequestTenancyMiddleware, RequestTenancyOptions, DisableMultiTenancyAttribute
Ayaka.MultiTenancy.AspNetCore.DetectionITenantDetectionStrategy and the built-in strategies
Ayaka.MultiTenancy.AspNetCore.ResolutionITenantContextResolver

What Ayaka does not do ​

Your application decides how the tenant identity affects its data and services. Ayaka does not filter database queries, choose connection strings, provision databases, authenticate users, or check whether a user belongs to a tenant. Selecting a tenant, whether from a header, a host, or anything else the caller controls, establishes which tenant a request targets, not that the caller may access it; your authorization policies decide that.

Where to go next ​

Released under the MIT License.