CleanArchitecture.Extensions.Multitenancy.AspNetCore 0.2.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package CleanArchitecture.Extensions.Multitenancy.AspNetCore --version 0.2.7
                    
NuGet\Install-Package CleanArchitecture.Extensions.Multitenancy.AspNetCore -Version 0.2.7
                    
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="CleanArchitecture.Extensions.Multitenancy.AspNetCore" Version="0.2.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CleanArchitecture.Extensions.Multitenancy.AspNetCore" Version="0.2.7" />
                    
Directory.Packages.props
<PackageReference Include="CleanArchitecture.Extensions.Multitenancy.AspNetCore" />
                    
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 CleanArchitecture.Extensions.Multitenancy.AspNetCore --version 0.2.7
                    
#r "nuget: CleanArchitecture.Extensions.Multitenancy.AspNetCore, 0.2.7"
                    
#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 CleanArchitecture.Extensions.Multitenancy.AspNetCore@0.2.7
                    
#: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=CleanArchitecture.Extensions.Multitenancy.AspNetCore&version=0.2.7
                    
Install as a Cake Addin
#tool nuget:?package=CleanArchitecture.Extensions.Multitenancy.AspNetCore&version=0.2.7
                    
Install as a Cake Tool

CleanArchitecture.Extensions.Multitenancy.AspNetCore

ASP.NET Core adapter for CleanArchitecture.Extensions.Multitenancy. It provides middleware to resolve tenants from HTTP requests, endpoint filters for enforcement, and helpers for minimal APIs and MVC.

What you get

  • Tenant resolution middleware that builds TenantResolutionContext from HttpContext.
  • Minimal API endpoint filter (TenantEnforcementEndpointFilter).
  • MVC action filter (TenantEnforcementActionFilter).
  • Endpoint metadata helpers (RequireTenant, AllowAnonymousTenant, WithTenantHeader, WithTenantRoute).
  • ProblemDetails mapping for multitenancy exceptions.
  • Exception handler integration (TenantExceptionHandler) for consistent ProblemDetails responses.
  • Optional startup filters to auto-add the middleware and the default exception handler when you cannot modify Program.cs.

Install

dotnet add package CleanArchitecture.Extensions.Multitenancy.AspNetCore

Quickstart

1) Register services

using CleanArchitecture.Extensions.Multitenancy.AspNetCore;

builder.Services.AddCleanArchitectureMultitenancyAspNetCore(
    autoUseMiddleware: true,
    autoUseExceptionHandler: true); // default for the template

Use autoUseMiddleware when header or host resolution is enough and you do not depend on route values. For claim- or route-based resolution, disable it and place app.UseCleanArchitectureMultitenancy() after authentication or routing. autoUseExceptionHandler is enabled by default to work around the template's UseExceptionHandler(options => { }) stub; disable it if you already call app.UseExceptionHandler() with the new IExceptionHandler pipeline intact.

2) Add the middleware (manual)

using CleanArchitecture.Extensions.Multitenancy.AspNetCore.Middleware;

app.UseCleanArchitectureMultitenancy();

Skip this step when you enable autoUseMiddleware.

3) Enforce tenancy (minimal APIs)

using CleanArchitecture.Extensions.Multitenancy.AspNetCore.Routing;

app.MapGroup("/tenants/{tenantId}")
    .AddTenantEnforcement()
    .RequireTenant()
    .MapGet("/profile", () => Results.Ok());

4) Enforce tenancy (MVC)

using CleanArchitecture.Extensions.Multitenancy.AspNetCore;

builder.Services
    .AddControllers()
    .AddMultitenancyEnforcement();

Options

using CleanArchitecture.Extensions.Multitenancy.AspNetCore;
using CleanArchitecture.Extensions.Multitenancy.AspNetCore.Options;
using CleanArchitecture.Extensions.Multitenancy.Configuration;

builder.Services.AddCleanArchitectureMultitenancyAspNetCore(
    autoUseExceptionHandler: true,
    coreOptions =>
    {
        coreOptions.HeaderNames = new[] { "X-Tenant-ID" };
        coreOptions.RouteParameterName = "tenantId";
        coreOptions.QueryParameterName = "tenantId";
    },
    aspNetOptions =>
    {
        aspNetOptions.CorrelationIdHeaderName = "X-Correlation-ID";
        aspNetOptions.StoreTenantInHttpContextItems = true;
        aspNetOptions.EnableOpenApiIntegration = true;
    });

Template defaults (JaysonTaylorCleanArchitectureBlank)

  • Prefer header or host resolution to keep the template unchanged.
  • Route-based tenancy requires routing middleware before multitenancy; opt in only if you can adjust the pipeline.

Example for route-based tenants (note the default exception handler already runs):

app.UseRouting();
app.UseCleanArchitectureMultitenancy();
app.MapEndpoints();

ProblemDetails mapping

Use TenantProblemDetailsMapper when you want to turn multitenancy exceptions into HTTP responses:

using CleanArchitecture.Extensions.Multitenancy.AspNetCore.ProblemDetails;

if (TenantProblemDetailsMapper.TryCreate(exception, httpContext, out var details))
{
    return Results.Problem(details);
}

Notes

  • This adapter depends on the core multitenancy package and wires its services automatically.
  • MediatR behaviors still live in the core package (AddCleanArchitectureMultitenancyPipeline).
  • The middleware stores the resolved TenantContext in HttpContext.Items by default.
  • GetTenantContext() respects the configured AspNetCoreMultitenancyOptions.HttpContextItemKey when available.
  • AddCleanArchitectureMultitenancyAspNetCore registers TenantExceptionHandler so UseExceptionHandler can map multitenancy exceptions to ProblemDetails.
  • Keep autoUseExceptionHandler enabled (default) when the host pipeline does not call UseExceptionHandler() (or overrides it), so your registered IExceptionHandler implementations still run.
  • Set AspNetCoreMultitenancyOptions.EnableOpenApiIntegration to false to disable ApiExplorer/OpenAPI adjustments.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.9 91 1/13/2026
0.2.8 90 1/13/2026
0.2.7 97 1/13/2026
0.2.6 91 1/12/2026
0.2.5 101 1/8/2026
0.2.4 92 1/3/2026
0.2.3 97 1/1/2026
0.2.2 96 1/1/2026
0.2.1 94 12/29/2025