Skip to content

AmbientTenantScope

Namespace AgentPrism · Assembly AgentPrism.Abstractions.dll

The ambient passing mechanism for running an operation executed in the background (outside an HTTP request) as a specific tenant.

public static class AmbientTenantScope

objectAmbientTenantScope

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

The ITenantContext implementations (the single-tenant default, the HTTP-based multi-tenant resolver) are singletons and read the tenant either from a fixed default or from HttpContext. Which tenant a scheduled job runs for is neither fixed nor lives in an HTTP context — it is carried inside JobRecord.TenantId. This class provides a pass-through using the same Threading.AsyncLocal pattern IHttpContextAccessor uses: while the value is set, both ITenantContext implementations check it before their own default resolution.

The current ambient tenant if set right now; null otherwise.

public static string? Current { get; }

string?

Sets the ambient tenant for the duration of the scope.

public static IDisposable Begin(string tenantId)

tenantId string

The tenant identifier to use for the duration of the scope.

IDisposable

An object that restores the previous value when IDisposable.Dispose is called. Nested use is safe.

ArgumentException

tenantId is empty or whitespace only.