TenantContextPropagation class
Namespace: Tenantry.Pro.BackgroundServices · Package: Tenantry.Pro · API reference
Shared tenant-resolution logic for the Tenantry.Pro background-job and messaging integrations. Parses a tenant identifier carried by a job/message, looks it up in the store, and applies the configured MissingTenantBehavior when no tenant can be resolved.
This consolidates the resolve → parse → lookup → policy logic that every integration (Hangfire, MassTransit, Quartz, Rebus) would otherwise duplicate, so the missing-tenant behaviour stays consistent across all of them.
public static class TenantContextPropagationMethods
ResolveAsync<TKey>(string?, MissingTenantBehavior, ITenantStoreAccessor<TKey>, ILogger, string, CancellationToken)
Resolves the tenant for an incoming job/message asynchronously.
public static ValueTask<TenantPropagationDecision<TKey>> ResolveAsync<TKey>(string? rawTenantId, MissingTenantBehavior onMissingTenant, ITenantStoreAccessor<TKey> storeAccessor, ILogger logger, string carrier, CancellationToken cancellationToken = default) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
rawTenantIdstring: The tenant identifier carried by the job/message, or null if none.onMissingTenantMissingTenantBehavior: The policy to apply when no tenant can be resolved.storeAccessorITenantStoreAccessor<TKey>: Resolves tenants from the store.loggerILogger: Logger for warning/skip diagnostics.carrierstring: A short description of the job/message for log messages (e.g."Hangfire job 42").cancellationTokenCancellationToken: A cancellation token.
Returns: ValueTask<TenantPropagationDecision<TKey>>
Exceptions:
TenantNotResolvedException: Thrown when no tenant can be resolved andonMissingTenantisReject.
Resolve<TKey>(string?, MissingTenantBehavior, ITenantStoreAccessor<TKey>, ILogger, string)
Resolves the tenant for an incoming job/message synchronously. Intended for callers (such as Hangfire server filters) whose pipeline is synchronous; the store lookup blocks the calling thread, which is acceptable on a background worker thread.
public static TenantPropagationDecision<TKey> Resolve<TKey>(string? rawTenantId, MissingTenantBehavior onMissingTenant, ITenantStoreAccessor<TKey> storeAccessor, ILogger logger, string carrier) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
rawTenantIdstring: The tenant identifier carried by the job/message, or null if none.onMissingTenantMissingTenantBehavior: The policy to apply when no tenant can be resolved.storeAccessorITenantStoreAccessor<TKey>: Resolves tenants from the store.loggerILogger: Logger for warning/skip diagnostics.carrierstring: A short description of the job/message for log messages (e.g."Hangfire job 42").
Returns: TenantPropagationDecision<TKey>
Exceptions:
TenantNotResolvedException: Thrown when no tenant can be resolved andonMissingTenantisReject.