ITenantContextSetter<TKey> interface
Namespace: Tenantry · Package: Tenantry.Core · API reference
Makes a tenant current for the calling code, for code that has already found the tenant and needs no new dependency-injection scope. Most code uses ITenantScopeFactory<TKey> instead, which also creates a scope for the tenant's services.
Registered as a singleton by AddTenantry. The current tenant is ambient (held in an AsyncLocal<T>): it flows into code the caller awaits or starts, never back to the caller's caller.
public interface ITenantContextSetter<TKey> : ITenantContext<TKey> where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters
TKey: The tenant identifier type. SeeITenantDescriptor<TKey>for constraints.
Methods
Use(ITenantDescriptor<TKey>)
Makes tenant the current tenant until the returned handle is disposed. Uses may nest: an inner one shadows the outer tenant, and disposing it restores the outer tenant (the outermost one restores "no tenant").
IDisposable Use(ITenantDescriptor<TKey> tenant)Parameters:
tenantITenantDescriptor<TKey>: The tenant to make current.
Returns: IDisposable: A handle that restores the previously current tenant on disposal.
Exceptions:
ArgumentException: The tenant's id is the key type's default value (Empty,0) or an empty string, which Tenantry reserves for "no tenant".
ITenantContext<TKey> interface
Provides read-only access to the currently resolved tenant for the active request scope.
ITenantDescriptor interface
A tenant, without its identifier type: the base of ITenantDescriptor<TKey>tenantry-itenantdescriptor-1.md, for code that does not need the tenant's id, such as TenantDescriptorExtensions.As<TTenant>tenantry-tenantdescriptorextensions.md.