Tenantry ProAPI reference
TenantryProHangfireBuilderExtensions class
Namespace: Microsoft.Extensions.DependencyInjection · Package: Tenantry.Pro.Hangfire · API reference
Extension methods for adding the Hangfire integration on IProBuilder<TKey>.
public static class TenantryProHangfireBuilderExtensionsMethods
AddHangfirePropagation<TKey>(IProBuilder<TKey>, Action<TenantPropagationOptions>?)
Makes a Hangfire job carry the tenant that was current when it was enqueued, and run as that tenant: its scoped services, created in the job's scope, see the tenant. Wire it into Hangfire with UseTenantry(sp) on Hangfire's configuration.
public static IProBuilder<TKey> AddHangfirePropagation<TKey>(this IProBuilder<TKey> pro, Action<TenantPropagationOptions>? configure = null) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
proIProBuilder<TKey>: The Pro builder.configureAction<TenantPropagationOptions>: Sets what happens to a job that carries no tenant (TenantPropagationOptions.OnMissingTenant, Warn by default) or a tenant the store does not have (TenantPropagationOptions.OnUnresolvedTenant, Reject by default).
Returns: IProBuilder<TKey>: The same pro for chaining.
The application fails to start if Hangfire's configuration never calls UseTenantry(sp), which would leave jobs without their tenant. Calling this again adds configure to the same options.
builder.Services.AddTenantry<string>(tenant => tenant
.UseStore<MyTenantStore>()
.UsePro(pro => pro.AddHangfirePropagation()));
builder.Services.AddHangfire((sp, config) => config
.UseSqlServerStorage(connectionString)
.UseTenantry(sp));