A job factory creates instances of scheduled Quartz.NET jobs. In ASP.NET Core, configure it to resolve job implementations from the dependency-injection container, allowing jobs to use registered services. section 34.3 section 34.3.1
The factory fits between the scheduler and the job:
- A trigger determines when a job should run. section 34.3
- The scheduler asks the job factory to create the job instance. section 34.3
- The dependency-injection job factory retrieves the implementation from ASP.NET Core’s DI container. section 34.3 section 34.3.1
Listing 34.10 Configuring Quartz.NET
using Quartz;
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) => #1
{
services.AddQuartz(q => #2
{
q. UseMicrosoftDependencyInjectionJobFactory(); #3
});
services.AddQuartzHostedService( #4
q => q.WaitForJobsToComplete = true); #4
})
.Build();
host.Run();
Configure Quartz.NET to use Microsoft’s dependency-injection job factory, then add the hosted scheduler. Setting WaitForJobsToComplete keeps shutdown from abandoning jobs already in progress. section 34.3.1
