Hello,
I’m trying to implement a custom JobActivator with the default ASP.NET Core 5.0 DI, because when a specific function is running with Hangfire, I want it to use another implementation of an interface. So I created my custom implementation, which looks like this:
public class HangfireJobActivator : JobActivator
{
private readonly IServiceProvider serviceProvider;
public HangfireJobActivator(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
public override object ActivateJob(Type jobType)
{
if (jobType == typeof(IUserProvider<Guid>))
return new TestUserProvider();
else
return serviceProvider.GetService(jobType);
}
}
But when the ActivateJob-method get’s called by Hangfire, it’ll throw an exception because the serviceProvider is already disposed. How can I fix this?