Interface ITenantContext
Read-only ambient accessor for the tenant identifier associated with the current execution flow.
public interface ITenantContext
- Extension Methods
Remarks
The ambient tenant flows through the logical call context (an AsyncLocal-backed
scope established by the tenant resolver / inbound middleware), never a thread-static
slot. This contract exposes no mutator: the ambient tenant is structurally immutable
through ITenantContext, and can only be established by the resolving
scope. Consumers read the current tenant; they cannot reassign it.
Invariant (history constraint). Across every implementation, the tenant scope observed for a given execution flow is preserved — never mutated or downgraded — through this contract: repeated reads within the same flow return the same value. Implementations MUST also keep HasTenant consistent with TenantId: HasTenant is true exactly when TenantId is a non-null, non-empty identifier. A behavioral subtype may not weaken this: it may not report a tenant present while exposing a null/empty id, nor silently switch the resolved tenant of a flow already in progress.
Properties
HasTenant
Gets a value indicating whether a tenant is resolved for the current execution flow.
bool HasTenant { get; }
Property Value
TenantId
Gets the identifier of the current ambient tenant.
string? TenantId { get; }