HangfireIO / HangfireIO/Hangfire
Hangfire and AutoFac - transient dependency to populate multitenant information
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
Consider the following, there's an interface, that holds a tenant ID property.
This interface is injected in a per-request scope, can it be either via an API call, a background thread, a message handler, etc.
Within this scope, I need to be able to schedule a recurring job, where the recurring job holds the tenant ID as a job parameter.
This, I tried using a custom filter. However, I fail to understand how I can get the current ILifetimeScope instead of the root lifetimescope.
I have the following:
` public class MultiTenantJobFilterAttribute : JobFilterAttribute
{
}
public class MultiTenantJobFilter : IClientFilter
{
private readonly ILifetimeScope _lifetimeScope;
public MultiTenantJobFilter(ILifetimeScope lifetimeScope)
{
_lifetimeScope = lifetimeScope;
}
public void OnCreated(CreatedContext filterContext)
{
}
public void OnCreating(CreatingContext filterContext)
{
if (filterContext == null) throw new ArgumentNullException(nameof(filterContext));
var reqCtx = _lifetimeScope.Resolve();
filterContext.SetJobParameter("TenantId", reqCtx.TenantId);
}
}`
Tried registering the filter, but this filter needs the correct scope, which I cannot pass when registering the filter using IConfiguration.UseFilter.
What would be the best approach here?
Contributor guide
Assessment
This issue has not been assessed yet.