CleanArchitecture.Extensions.Multitenancy 0.1.8-preview.3

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

CleanArchitecture.Extensions.Multitenancy

Core multitenancy primitives and MediatR behaviors for the JasonTaylorCleanArchitectureBlank template.

Step 1 - Install the package

Install in both Application and Infrastructure projects:

dotnet add src/Application/Application.csproj package CleanArchitecture.Extensions.Multitenancy
dotnet add src/Infrastructure/Infrastructure.csproj package CleanArchitecture.Extensions.Multitenancy

Step 2 - Register multitenancy services (Infrastructure layer)

File: src/Infrastructure/DependencyInjection.cs

using CleanArchitecture.Extensions.Multitenancy;
using CleanArchitecture.Extensions.Multitenancy.Configuration;

public static void AddInfrastructureServices(this IHostApplicationBuilder builder)
{
    // existing registrations...

    builder.Services.AddCleanArchitectureMultitenancy(options =>
    {
        options.HeaderNames = new[] { "X-Tenant-ID" };
        options.RouteParameterName = "tenantId";
        options.QueryParameterName = "tenantId";
        options.ClaimType = "tenant_id";
    });
}

Optional: when using caching, register the tenant-aware cache scope after caching services:

builder.Services.AddCleanArchitectureCaching();
builder.Services.AddCleanArchitectureMultitenancyCaching();

Step 3 - Register multitenancy behaviors (Application layer)

File: src/Application/DependencyInjection.cs

using CleanArchitecture.Extensions.Multitenancy.Behaviors;

builder.Services.AddMediatR(cfg =>
{
    cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
    cfg.AddOpenRequestPreProcessor(typeof(LoggingBehaviour<>));
    cfg.AddOpenBehavior(typeof(UnhandledExceptionBehaviour<,>));
    cfg.AddOpenBehavior(typeof(AuthorizationBehaviour<,>));
    cfg.AddOpenBehavior(typeof(ValidationBehaviour<,>));
    // Add multitenancy behaviors below this line ----
    cfg.AddOpenBehavior(typeof(TenantValidationBehavior<,>));
    cfg.AddOpenBehavior(typeof(TenantEnforcementBehavior<,>));
    cfg.AddOpenBehavior(typeof(TenantCorrelationBehavior<,>));
    // Add multitenancy behaviors above this line ----
    cfg.AddOpenBehavior(typeof(PerformanceBehaviour<,>));
});

Step 4 - Use tenant context

The core package stores tenant context in an AsyncLocal accessor. Web-specific resolution is provided by the CleanArchitecture.Extensions.Multitenancy.AspNetCore package; background workers can set the context manually:

using CleanArchitecture.Extensions.Multitenancy.Abstractions;

public class TenantJob
{
    private readonly ITenantAccessor _tenantAccessor;

    public TenantJob(ITenantAccessor tenantAccessor)
    {
        _tenantAccessor = tenantAccessor;
    }

    public Task ExecuteAsync()
    {
        var tenant = new TenantInfo("tenant-1");
        using var scope = _tenantAccessor.BeginScope(new TenantContext(tenant, TenantResolutionResult.Resolved("tenant-1", TenantResolutionSource.Custom)));
        // do work within tenant boundary
        return Task.CompletedTask;
    }
}
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 (3)

Showing the top 3 NuGet packages that depend on CleanArchitecture.Extensions.Multitenancy:

Package Downloads
CleanArchitecture.Extensions.Multitenancy.AspNetCore

ASP.NET Core adapters for Clean Architecture multitenancy middleware, endpoint enforcement, and HTTP resolution.

CleanArchitecture.Extensions.Multitenancy.EFCore

EF Core adapters for Clean Architecture multitenancy, including tenant-aware filters, interceptors, and DbContext helpers.

CleanArchitecture.Extensions.Multitenancy.Caching

Tenant-aware caching integration for Clean Architecture multitenancy, including cache scope binding and cache-scope warnings.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.9 133 1/13/2026
0.2.8 133 1/13/2026
0.2.7 121 1/13/2026
0.2.6 122 1/12/2026
0.2.5 138 1/8/2026
0.2.4 128 1/3/2026
0.2.3 121 1/1/2026
0.2.2 126 1/1/2026
0.2.1 113 12/29/2025
0.2.0 103 12/29/2025
0.1.8-preview.3 65 12/28/2025