Table of Contents

Class QuartzHostApplicationBuilderExtensions

Namespace
Quartz
Assembly
Quartz.dll

Registers Quartz on a host application builder, which is how an application built by Host.CreateApplicationBuilder or WebApplication.CreateBuilder adds anything else.

public static class QuartzHostApplicationBuilderExtensions
Inheritance
QuartzHostApplicationBuilderExtensions
Inherited Members

Remarks

These are the IServiceCollection overloads with the application's configuration already found. A builder has both halves — its services and its configuration — so builder.AddQuartz(…) reads the Quartz configuration section without being handed it, which is what the two-line builder.Services.AddQuartz(builder.Configuration.GetSection("Quartz"), …) was for.

Nothing is removed: builder.Services.AddQuartz(…) keeps working and means what it always did, including with a configuration section of a different name.

Methods

AddQuartz(IHostApplicationBuilder, Action<IQuartzBuilder>?)

Registers a Quartz scheduler, configured from the application's Quartz configuration section.

public static IHostApplicationBuilder AddQuartz(this IHostApplicationBuilder builder, Action<IQuartzBuilder>? configure = null)

Parameters

builder IHostApplicationBuilder

The host application builder.

configure Action<IQuartzBuilder>

Configures the scheduler, over whatever the section said.

Returns

IHostApplicationBuilder

Remarks

An application with no such section gets a scheduler configured entirely by configure, which is what services.AddQuartz(configure) would have given it.

AddQuartz(IHostApplicationBuilder, string, Action<IQuartzBuilder>?)

Registers a named Quartz scheduler, configured from the application's Quartz configuration section.

public static IHostApplicationBuilder AddQuartz(this IHostApplicationBuilder builder, string name, Action<IQuartzBuilder>? configure = null)

Parameters

builder IHostApplicationBuilder

The host application builder.

name string

The scheduler's name.

configure Action<IQuartzBuilder>

Configures the scheduler, over whatever the section said.

Returns

IHostApplicationBuilder

Remarks

The name is the scheduler's, exactly as in services.AddQuartz(name, …) — a string means a scheduler here as it does everywhere else in Quartz, never a configuration section. Its settings are read from Quartz:Schedulers:<name> when the section describes several schedulers.

AddQuartzHostedService(IHostApplicationBuilder, Action<QuartzHostedServiceOptions>?)

Adds the hosted service that starts and stops every scheduler in the container with the application.

public static IHostApplicationBuilder AddQuartzHostedService(this IHostApplicationBuilder builder, Action<QuartzHostedServiceOptions>? configure = null)

Parameters

builder IHostApplicationBuilder

The host application builder.

configure Action<QuartzHostedServiceOptions>

Configures how the schedulers are started and stopped.

Returns

IHostApplicationBuilder

AddQuartzHostedService(IHostApplicationBuilder, string, Action<QuartzHostedServiceOptions>?)

Configures how one named scheduler is started and stopped by the hosted service.

public static IHostApplicationBuilder AddQuartzHostedService(this IHostApplicationBuilder builder, string schedulerName, Action<QuartzHostedServiceOptions>? configure = null)

Parameters

builder IHostApplicationBuilder

The host application builder.

schedulerName string

The name the scheduler was registered under.

configure Action<QuartzHostedServiceOptions>

Configures how that scheduler is started and stopped.

Returns

IHostApplicationBuilder

AddQuartzHostedService<T>(IHostApplicationBuilder, Action<QuartzHostedServiceOptions>?)

Adds a hosted service of your own deriving from QuartzHostedService.

public static IHostApplicationBuilder AddQuartzHostedService<T>(this IHostApplicationBuilder builder, Action<QuartzHostedServiceOptions>? configure = null) where T : QuartzHostedService

Parameters

builder IHostApplicationBuilder

The host application builder.

configure Action<QuartzHostedServiceOptions>

Configures how the schedulers are started and stopped.

Returns

IHostApplicationBuilder

Type Parameters

T

Type extending the QuartzHostedService class.

AddQuartzSchedulers(IHostApplicationBuilder, Action<IQuartzBuilder>?)

Registers one named Quartz scheduler per child of the Quartz section's Schedulers sub-section.

public static IHostApplicationBuilder AddQuartzSchedulers(this IHostApplicationBuilder builder, Action<IQuartzBuilder>? configure = null)

Parameters

builder IHostApplicationBuilder

The host application builder.

configure Action<IQuartzBuilder>

Applied to every scheduler described by the section.

Returns

IHostApplicationBuilder

Remarks

This is AddQuartzSchedulers(IServiceCollection, IConfiguration, Action<IQuartzBuilder>?) with the section found for you, and it says exactly what that one says — including refusing a section that describes one scheduler rather than several.

The receiver decides where configuration comes from, and it decides it the same way for every method here: a service collection is handed its configuration, a builder already holds its own. That is why this takes no IConfiguration and the service collection overload requires one — the same difference AddQuartz has, for the same reason. Neither receiver goes looking for a configuration it was not given: services.AddQuartz(configure) means a scheduler configured entirely in code, not one that quietly reads whatever IConfiguration the container happens to hold, and there is no services.AddQuartzSchedulers(configure) because a fan-out with nothing to fan out over is not a scheduler registration at all.