Hangfire
Hangfire copied to clipboard
Any way to access JobActivator/Scope in JobFilter and replace job parameters?
trafficstars
Why do I need this: I'm trying to replace PerformContext-like object in my job execution method parameters.
So the first thing I've encountered is: I can't get current activator scope, therefore I can't resolve the needed parameter within the scope.
The second problem is: I can't find a way to replace job parameters since filterContext.BackgroundJob.Job.Args is readonly.
This is a sample which demonstrates the problem:
public void OnPerforming(PerformingContext filterContext)
{
var jobContextParameter = filterContext.BackgroundJob.Job.Method.GetParameters()
.FirstOrDefault(f => f.ParameterType == typeof(IJobContext));
if (jobContextParameter != null)
{
filterContext.BackgroundJob.Job.Args[0] = container.Resolve<IJobContext>();
}
}