Pular para o conteúdo principal
Versão: 10.4.1

ITLab.Template.DevPack.Identity.MultiTenancy

Provides the tenant resolution pipeline: contracts, contributor base classes, context and result types.

Componentes

TipoNomeResponsabilidade
InterfaceITenantResolverCoordinates registered contributors and produces a TenantResolveResult
InterfaceITenantResolveContributorContract for a single tenant resolution strategy
ClassTenantResolveContributorBaseBase class with shared contributor lifecycle
InterfaceITenantResolveContextProvides request-scoped data for contributors to inspect
ClassTenantResolveContextDefault implementation of ITenantResolveContext
ClassTenantResolutionInfoCarries the resolved tenant identifier and contributing source
ClassTenantResolveResultFinal outcome of the resolution pipeline (resolved / unresolved)
ClassTenantResolveOptionsConfigures the ordered list of active contributors
InterfaceITenantAccessValidatorValidates 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 ITenantAccessValidator when 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 ITenantResolveContributor for product-specific resolution strategies (e.g. subdomain, API key).
  • Products implement ITenantAccessValidator to enforce tenant isolation rules.