LinKit.Tenancy
1.2.1
dotnet add package LinKit.Tenancy --version 1.2.1
NuGet\Install-Package LinKit.Tenancy -Version 1.2.1
<PackageReference Include="LinKit.Tenancy" Version="1.2.1" />
<PackageVersion Include="LinKit.Tenancy" Version="1.2.1" />
<PackageReference Include="LinKit.Tenancy" />
paket add LinKit.Tenancy --version 1.2.1
#r "nuget: LinKit.Tenancy, 1.2.1"
#:package LinKit.Tenancy@1.2.1
#addin nuget:?package=LinKit.Tenancy&version=1.2.1
#tool nuget:?package=LinKit.Tenancy&version=1.2.1
LinKit.Tenancy
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 | 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 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. |
-
net10.0
- LinKit.Core (>= 3.2.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
-
net8.0
- LinKit.Core (>= 3.2.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
-
net9.0
- LinKit.Core (>= 3.2.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.