Configuring Quartz.Net To Use A Custom Job Factory

In an earlier post we covered what Quartz.Net job factories are and what they’re used for. We also went over the job factories that are included in the Quartz.Net distribution. For this post we’ll cover how to configure the Quartz.Net scheduler so that it uses the job factory we want.

To demonstrate how this is done we’ll modify the quartz.config file and tell Quartz.Net to use a PropertySettingJobFactory instead of the default SimpleJobFactory.

To do this we will need to add these 3 lines to the quartz.config properties file:

quartz.scheduler.jobFactory.type = Quartz.Simpl.PropertySettingJobFactory, Quartz
quartz.scheduler.jobFactory.ThrowIfPropertyNotFound = false
quartz.scheduler.jobFactory.WarnIfPropertyNotFound = false

Alternatively, if you are configuring Quartz.Net using the application’s configuration file, it would look something like this:

<add key=”quartz.scheduler.jobFactory.type” value=”Quartz.Simpl.PropertySettingJobFactory, Quartz”/>
<add key=”quartz.scheduler.jobFactory.ThrowIfPropertyNotFound” value=”false”/>
<add key=”quartz.scheduler.jobFactory.WarnIfPropertyNotFound” value=”false”/>

Description of the Properties

Let’s look at the properties we are setting and describe them with a little bit of detail.

quartz.scheduler.factory.type

This property sets the Type of the job. The type is the .Net type of your job factory, and it should be specified with it’s fully qualified name followed by the assembly name (without the .dll extension).

quartz.scheduler.jobFactory.x

The quartz.scheduler.jobFactory is a prefix that indicates that any name following the prefix is a property on the job factory type you specified. The scheduler will then try to set the property on the job factory that matches the name specified in the configuration file. In our example we have specified the two properties supported by the PropertySettingJobFactory

That’s really all there is to it. With this configuration, every time the scheduler needs to create a job, it will use the PropertySettingJobFactory to create it. If you want to specify your own custom job factory, simply specify your job factory’s type in the quartz.scheduler.jobFactory.type property.