On my .Net 5 ASP.NET application at Startup.cs I have the follwing (for Hangfire):
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
{
...
GlobalConfiguration.Configuration.UseActivator(new ServiceProviderJobActivator(serviceProvider));
...
}
I want to move to the .Net 6 way of configuration (in Program.cs), but I don't know how to get an instance of IServiceProvider to provide to the ServiceProviderJobActivator method.
The method is:
internal class ServiceProviderJobActivator : Hangfire.JobActivator
{
private readonly IServiceProvider _serviceProvider;
public ServiceProviderJobActivator(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public override object ActivateJob(Type type)
{
return _serviceProvider.GetService(type);
}
}
I have tried:
GlobalConfiguration.Configuration.UseActivator(new ServiceProviderJobActivator(app.Services));
I also tried:
public override object ActivateJob(Type type)
{
return _serviceProvider.GetRequiredService(type);
}
but the ActivateJob returns null in both cases
Thanks