v2 Migration Guide¶
This document will describe the changes made in v2 of NCronJob and how to migrate from v1.
Version 2 of NCronJob brings some breaking changes to make a better API.
CronExpression moved towards builder¶
In v1 one would define as such:
services.AddNCronJob();
services.AddCronJob<PrintHelloWorld>(options =>
{
options.CronExpression = "* * * * *";
options.Parameter = "Hello World";
});
With v2 the CronExpression is moved towards the builder pattern and AddCronJob is merged into AddNCronJob:
Services.AddNCronJob(options =>
{
options.AddJob<PrintHelloWorld>(j =>
{
j.WithCronExpression("* * * * *")
.WithParameter("Hello World");
});
});
This allows to easily define multiple jobs without adding much boilerplate code.
Services.AddNCronJob(options =>
{
options.AddJob<PrintHelloWorld>(p => p
.WithCronExpression("0 * * * *").WithParameter("Foo")
.And
.WithCronExpression("0 0 * * *").WithParameter("Bar"));
});