Muonroi.Tenancy.Abstractions
1.0.0-alpha.16
dotnet add package Muonroi.Tenancy.Abstractions --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.Tenancy.Abstractions -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.Tenancy.Abstractions" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.Tenancy.Abstractions" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.Tenancy.Abstractions" />
paket add Muonroi.Tenancy.Abstractions --version 1.0.0-alpha.16
#r "nuget: Muonroi.Tenancy.Abstractions, 1.0.0-alpha.16"
#:package Muonroi.Tenancy.Abstractions@1.0.0-alpha.16
#addin nuget:?package=Muonroi.Tenancy.Abstractions&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.Tenancy.Abstractions&version=1.0.0-alpha.16&prerelease
Muonroi.Tenancy.Abstractions
Contracts-only package that defines the multi-tenancy interfaces, options, and models shared across every Muonroi service.
This package ships the contracts (ITenantContext, ITenantIdResolver, ITenantConnectionStringFactory, ITenantScoped) and configuration types (MultiTenantOptions, TenantConnectionStringsOptions) that the rest of the Muonroi tenancy stack depends on. It contains no runtime behavior — register it as a reference in libraries that need the interfaces; use Muonroi.Tenancy.Core for the concrete implementations and Muonroi.Tenancy for ASP.NET middleware.
Installation
dotnet add package Muonroi.Tenancy.Abstractions --prerelease
Quick Start
Because this is a contracts package, the typical usage is either consuming an injected ITenantContext inside a service, or implementing one of the interfaces in your own class.
Consuming the injected context
// In a controller or service — ITenantContext is registered by Muonroi.Tenancy.Core
public class OrderService(ITenantContext tenantContext)
{
public Task<IEnumerable<Order>> GetOrdersAsync()
{
string? tenantId = tenantContext.TenantId;
// use tenantId to scope the query
}
}
Implementing a custom tenant-ID resolver
using Muonroi.Tenancy.Abstractions.Interfaces;
public class JwtTenantIdResolver : ITenantIdResolver
{
public Task<string?> ResolveTenantIdAsync(HttpContext context)
{
string? tenantId = context.User.FindFirst("tid")?.Value;
return Task.FromResult(tenantId);
}
}
// Registration (in your host project that references Muonroi.Tenancy.Core):
builder.Services.AddScoped<ITenantIdResolver, JwtTenantIdResolver>();
Registering options from configuration
builder.Services.Configure<MultiTenantOptions>(
builder.Configuration.GetSection(MultiTenantOptions.SectionName)); // "MultiTenantConfigs"
builder.Services.Configure<TenantConnectionStringsOptions>(
builder.Configuration.GetSection(TenantConnectionStringsOptions.SectionName)); // "TenantConnectionStrings"
// appsettings.json
{
"MultiTenantConfigs": {
"Enabled": true,
"RequireTenantClaimForAuthenticatedUser": true,
"Strategy": "SharedSchema",
"EnableRowLevelSecurity": false
},
"TenantConnectionStrings": {
"ConnectionStrings": {
"acme": "Host=db-acme;Database=acme;Username=app;Password=secret",
"beta": "Host=db-beta;Database=beta;Username=app;Password=secret"
}
}
}
For a complete working example — including TenantContext, DefaultTenantIdResolver, TenantSchemaSelector, MappingTenantConnectionStringFactory, and TenantResolutionMiddleware — see the Quickstart.Tenancy sample.
Features
ITenantContext— get/set the ambientTenantIdfor the current execution scope.ITenantIdResolver— extract a tenant ID from anHttpContextasynchronously.ITenantConnectionStringFactory— resolve a connection string by tenant ID.ITenantScoped— marker interface for domain entities and services that belong to a single tenant.MultiTenantOptions— enable/disable multi-tenancy, pick isolation strategy (SharedSchema,SeparateSchema,SeparateDatabase), and opt in to PostgreSQL Row-Level Security.TenantConnectionStringsOptions— map tenant IDs to connection strings viaappsettings.json.TenantIsolationStrategyenum — three isolation levels consumed by the runtime layer.NoOpTenantContext— null-objectITenantContextfor single-tenant or test scenarios.ITenantLicenseFeatureGate— check whether a tenant has a named license feature enabled.TenantLicenseFeatures.Premium.MultiTenant— well-known feature-name constant for multi-tenancy license gating.- Legacy contracts (
Muonroi.Tenancy.Abstractions.Legacy) —ITenantContextandITenantIdResolverkept for backward compatibility; prefer the canonical types above for new code.
Configuration
MultiTenantOptions binds from the "MultiTenantConfigs" section:
| Property | Type | Default | Description |
|---|---|---|---|
Enabled |
bool |
true |
Master switch for multi-tenant features |
RequireTenantClaimForAuthenticatedUser |
bool |
true |
Enforce tenant claim on authenticated requests |
Strategy |
TenantIsolationStrategy |
SharedSchema |
Data isolation model |
EnableRowLevelSecurity |
bool |
false |
PostgreSQL RLS (SET app.current_tenant_id) on every connection |
TenantConnectionStringsOptions binds from the "TenantConnectionStrings" section:
| Property | Type | Description |
|---|---|---|
ConnectionStrings |
Dictionary<string, string> |
Map of tenant ID → connection string |
API Reference
| Type | Purpose |
|---|---|
ITenantContext |
Get/set TenantId for the ambient execution scope |
ITenantIdResolver |
Resolve a tenant ID from an HttpContext |
ITenantConnectionStringFactory |
Return a connection string for a given tenant ID |
ITenantScoped |
Marker for tenant-scoped types (exposes read-only TenantId) |
MultiTenantOptions |
Configuration: isolation strategy, RLS, claim enforcement |
TenantConnectionStringsOptions |
Per-tenant connection string map |
TenantIsolationStrategy |
Enum: SharedSchema / SeparateSchema / SeparateDatabase |
NoOpTenantContext |
Null-object ITenantContext; returns null TenantId |
ITenantLicenseFeatureGate |
Check if a tenant license feature is active |
TenantLicenseFeatures.Premium.MultiTenant |
Feature name constant "multi-tenant" |
Samples
- Quickstart.Tenancy — end-to-end example: registers
TenantContext,DefaultTenantIdResolver,MappingTenantConnectionStringFactory, andTenantResolutionMiddleware; exercises each via REST endpoints.
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.Tenancy.Core— concrete implementations:TenantContext(AsyncLocal),DefaultTenantIdResolver,MappingTenantConnectionStringFactory,TenantSchemaSelector.Muonroi.Tenancy— ASP.NET integration:TenantResolutionMiddlewareand Redis tenant cache.Muonroi.Tenancy.SiteProfile— site-profile multi-tenancy:ISiteProfile,AddSiteProfile<T>(), per-site DI isolation.Muonroi.Quota.Abstractions— quota contracts depended on by this package.Muonroi.Core.Abstractions— base platform contracts.
License
Apache-2.0. See LICENSE-APACHE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Quota.Abstractions (>= 1.0.0-alpha.16)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on Muonroi.Tenancy.Abstractions:
| Package | Downloads |
|---|---|
|
Muonroi.Tenancy.Core
Shared-database multi-tenancy core: EF Core global filters, tenant context propagation, and quota tracking. |
|
|
Muonroi.Governance.Abstractions
OSS contracts for license governance: ILicenseGuard, LicenseState, LicenseTier, policy interfaces, and fingerprint abstractions. |
|
|
Muonroi.Mediator
Mediator pattern implementation for Muonroi: command/query dispatching, pipeline behaviors, and validation integration. |
|
|
Muonroi.Messaging.Abstractions
Message bus contracts: IIntegrationEvent, IEventHandler, and message envelope types for Muonroi messaging integrations. |
|
|
Muonroi.Observability
OpenTelemetry integration for Muonroi: ActivitySource setup, metric counters, structured logging, and trace propagation. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.16 | 37 | 6/22/2026 |
| 1.0.0-alpha.15 | 285 | 5/31/2026 |
| 1.0.0-alpha.14 | 265 | 5/15/2026 |
| 1.0.0-alpha.13 | 217 | 5/2/2026 |
| 1.0.0-alpha.12 | 110 | 4/2/2026 |
| 1.0.0-alpha.11 | 162 | 4/2/2026 |
| 1.0.0-alpha.9 | 106 | 3/30/2026 |
| 1.0.0-alpha.8 | 351 | 3/28/2026 |
| 1.0.0-alpha.7 | 75 | 3/27/2026 |
| 1.0.0-alpha.5 | 73 | 3/27/2026 |
| 1.0.0-alpha.4 | 72 | 3/27/2026 |
| 1.0.0-alpha.3 | 75 | 3/27/2026 |
| 1.0.0-alpha.2 | 81 | 3/26/2026 |
| 1.0.0-alpha.1 | 120 | 3/8/2026 |