LinKit.Tenancy 1.2.1

dotnet add package LinKit.Tenancy --version 1.2.1
                    
NuGet\Install-Package LinKit.Tenancy -Version 1.2.1
                    
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="LinKit.Tenancy" Version="1.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LinKit.Tenancy" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="LinKit.Tenancy" />
                    
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 LinKit.Tenancy --version 1.2.1
                    
#r "nuget: LinKit.Tenancy, 1.2.1"
                    
#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 LinKit.Tenancy@1.2.1
                    
#: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=LinKit.Tenancy&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=LinKit.Tenancy&version=1.2.1
                    
Install as a Cake Tool

LinKit.Tenancy

NuGet

LinKit.Tenancy provides an asynchronous-flow tenant context and helpers to explicitly place/read a tenant ID in LinKit message headers. It does not automatically resolve HTTP identity, authorize a tenant, or filter database queries.

Install and register

dotnet add package LinKit.Tenancy
builder.Services.AddLinKitTenancy();

Inject ITenantContext into scoped application services:

public sealed class TenantOrderService(ITenantContext tenant, IOrderRepository orders)
{
    public Task<IReadOnlyList<Order>> GetOrdersAsync(CancellationToken cancellationToken)
    {
        var tenantId = tenant.TenantId
            ?? throw new InvalidOperationException("A tenant must be resolved before querying orders.");
        return orders.GetForTenantAsync(tenantId, cancellationToken);
    }
}

The application must validate the tenant ID and enforce isolation in authorization and data-access layers. Merely setting TenantId does not add a database filter.

Resolve and clear tenant context

The package does not install HTTP middleware or extract tenant headers for you. Resolve the tenant in application middleware, set the current context, and clear/restore it at the request or message-processing boundary:

var previous = tenantAccessor.Context;
try
{
    tenantAccessor.Context = new TenantContext { TenantId = validatedTenantId };
    await next();
}
finally
{
    tenantAccessor.Context = previous;
}

TenantAccessor uses AsyncLocal so context follows the asynchronous execution flow. Avoid passing tenant-bound work into detached/background tasks without explicitly copying the intended tenant context.

Propagate through message headers

var headers = new MessageHeaders();
TenantPropagation.Inject(headers, tenantContext.TenantId);

var incomingTenantId = TenantPropagation.Extract(headers);
if (incomingTenantId is not null)
{
    tenantAccessor.Context.TenantId = ValidateTenantId(incomingTenantId);
}

Generated consumers call every registered IMessageConsumeInterceptor per message. AddLinKitTenancy() registers TenantConsumeInterceptor, which sets the tenant from linkit-tenant-id for that message and restores the previous context afterwards. The header is trusted broker metadata, so only allow trusted publishers on the queue. Tenant data filtering still must be enforced by your data layer.

The message header key is linkit-tenant-id. TenantHeaderName (x-tenant-id) is a separate HTTP naming constant; the message helper does not automatically read/write HTTP headers or broker metadata.

License

MIT. See the repository license.

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 is compatible.  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 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
1.2.1 47 10/31/2026
1.2.0 43 10/30/2026
1.1.0 81 10/22/2026
1.0.0 82 10/20/2026