ITLab.Template.DevPack.Identity.MultiTenancy
Provides the tenant resolution pipeline: contracts, contributor base classes, context and result types.
Componentes
| Tipo | Nome | Responsabilidade |
|---|---|---|
| Interface | ITenantResolver | Coordinates registered contributors and produces a TenantResolveResult |
| Interface | ITenantResolveContributor | Contract for a single tenant resolution strategy |
| Class | TenantResolveContributorBase | Base class with shared contributor lifecycle |
| Interface | ITenantResolveContext | Provides request-scoped data for contributors to inspect |
| Class | TenantResolveContext | Default implementation of ITenantResolveContext |
| Class | TenantResolutionInfo | Carries the resolved tenant identifier and contributing source |
| Class | TenantResolveResult | Final outcome of the resolution pipeline (resolved / unresolved) |
| Class | TenantResolveOptions | Configures the ordered list of active contributors |
| Interface | ITenantAccessValidator | Validates whether the current user is allowed to access a resolved tenant |
Como usar
// Register tenant resolution in DI.
services.Configure<TenantResolveOptions>(opts =>
{
opts.TenantResolvers.Add<HeaderTenantResolveContributor>();
opts.TenantResolvers.Add<ClaimsTenantResolveContributor>();
});
services.AddScoped<ITenantResolver, TenantResolver>();
// Resolve tenant in middleware or a pipeline behavior.
var result = await tenantResolver.ResolveAsync(context);
if (result.TenantIdOrName is not null)
{
// The DevPack does not impose a single way to apply the resolved tenant.
// Consumers store it in their tenant accessor, attach it as a claim, or
// forward it to a custom `ICurrentUser` implementation. There is no
// built-in `ICurrentUser.SetTenant(...)` method.
}
O que não fazer
- Do not bypass
ITenantAccessValidatorwhen switching tenants on behalf of a user. - Do not hardcode tenant identifiers in contributors — source them from headers, claims or route data.
Extensão pelo produto
- Products implement
ITenantResolveContributorfor product-specific resolution strategies (e.g. subdomain, API key). - Products implement
ITenantAccessValidatorto enforce tenant isolation rules.