Tenantry ProAPI reference
TenantryBackgroundJobClientExtensions class
Namespace: Hangfire · Package: Tenantry.Pro.Hangfire · API reference
Extension methods for enqueueing a Hangfire job for a tenant other than the current one.
public static class TenantryBackgroundJobClientExtensionsMethods
ForTenant<TKey>(IBackgroundJobClient, TKey)
Returns a client whose jobs carry tenantId, so they run as that tenant (pro.AddHangfirePropagation()), whichever tenant is current, if any: for enqueueing on a tenant's behalf from code that runs without one, such as an administrator's request. Use it like the client it wraps.
public static IBackgroundJobClient ForTenant<TKey>(this IBackgroundJobClient client, TKey tenantId) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
clientIBackgroundJobClient: The application's client, such as theIBackgroundJobClientit injects.tenantIdTKey: The tenant's id. The tenant is looked up when the job runs.
Returns: IBackgroundJobClient: A client that creates every job for tenantId.
Exceptions:
ArgumentException:tenantIdis the key type's default value (Guid.Empty,0) or an empty string, which Tenantry reserves for "no tenant"; orclientcannot create a job with parameters (it does not implementIBackgroundJobClientV2, as Hangfire's own client does).
The tenant is stored in each job's parameters, under TenantPropagation.HeaderName, which Tenantry's job filter then leaves in place.
jobs.ForTenant(tenantId).Enqueue<ReportJob>(job => job.Execute());