Muonroi.Tenancy.Abstractions 1.0.0-alpha.16

This is a prerelease version of Muonroi.Tenancy.Abstractions.
dotnet add package Muonroi.Tenancy.Abstractions --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.Tenancy.Abstractions -Version 1.0.0-alpha.16
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Muonroi.Tenancy.Abstractions" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.Tenancy.Abstractions" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.Tenancy.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Muonroi.Tenancy.Abstractions --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.Tenancy.Abstractions, 1.0.0-alpha.16"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Muonroi.Tenancy.Abstractions@1.0.0-alpha.16
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Muonroi.Tenancy.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.Tenancy.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.Tenancy.Abstractions

Contracts-only package that defines the multi-tenancy interfaces, options, and models shared across every Muonroi service.

NuGet License: Apache 2.0

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 ambient TenantId for the current execution scope.
  • ITenantIdResolver — extract a tenant ID from an HttpContext asynchronously.
  • 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 via appsettings.json.
  • TenantIsolationStrategy enum — three isolation levels consumed by the runtime layer.
  • NoOpTenantContext — null-object ITenantContext for 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) — ITenantContext and ITenantIdResolver kept 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, and TenantResolutionMiddleware; exercises each via REST endpoints.

Compatibility

  • Target framework: net8.0
  • License: Apache-2.0 (OSS)

License

Apache-2.0. See LICENSE-APACHE.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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