liveBook · Manning

Job factory

As explained in ASP.NET Core in Action, 3e

A job factory is a Quartz.NET component that creates instances of scheduled jobs, including by resolving job implementations from a dependency-injection container.

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

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines the factory’s role and shows its configuration, but does not detail instance lifetimes or custom factory implementation.
Examples
Uses UseMicrosoftDependencyInjectionJobFactory inside AddQuartz configuration alongside AddQuartzHostedService.
What it assumes
Assumes familiarity with scheduled jobs and triggers while introducing the factory’s relationship with the scheduler and DI container.
What you can do after
Configure Quartz.NET to resolve scheduled job implementations from the ASP.NET Core dependency-injection container.
How it connects
Connects jobs, triggers, schedulers, hosted services, and dependency injection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.