Class MessageContextTenantFallbackExtensions
Extension applying the ambient-tenant fallback to a IMessageContext at construction.
public static class MessageContextTenantFallbackExtensions
- Inheritance
-
MessageContextTenantFallbackExtensions
- Inherited Members
Methods
ApplyAmbientTenantFallback(IMessageContext)
Falls back to Current when nothing more specific -- an inbound
header, a message's own metadata, a message's own ITenantAware.TenantId, or causal
propagation from a parent context -- has already supplied a tenant on context.
public static void ApplyAmbientTenantFallback(this IMessageContext context)
Parameters
contextIMessageContextThe message context to apply the fallback to.
Remarks
This reads Current directly rather than resolving
ITenantContext through DI. That distinction is load-bearing, not stylistic: on a
deployment that has not opted into multi-tenancy, ITenantContext resolves to the
default SingleTenantContext, whose TenantId is a FIXED, non-null constant
(DefaultTenantId) that ignores the ambient holder entirely -- so a
fallback sourced from ITenantContext cannot express "nothing is established here" on that
registration; it always answers with the default tenant, silently converting a genuinely
untenanted operation into an owned one. Current has no such
failure mode: it is null exactly when nothing established an ambient tenant for
the current async flow, regardless of which ITenantContext implementation (if any)
is registered.
Consequence: absence maps to leaving IMessageContext's tenant unset (which
folds to KeyedTenantPartition.Untenanted at the storage boundary) -- never to
DefaultTenantId. A deployment that has not established an ambient
tenant (including one that runs single-tenant and never calls TenantContextHolder.BeginScope
at all) is not promoted to the default tenant by this fallback; it stays untenanted, exactly as it
did before this fallback existed. This is deliberately narrower than "a single-tenant host gets
__default__ on every path" ambition -- doing that safely would require a way to distinguish
"this deployment is single-tenant by design" from "nothing was ever established here," which
TenantContextHolder cannot express and ITenantContext's default
registration answers wrongly. That narrower goal is a documented residual gap, not a silent one.
Never overwrites a value a more specific source already supplied -- call it only after any
header/metadata/ITenantAware/causal-propagation assignment, never before.
Exceptions
- ArgumentNullException
Thrown when
contextis null.