v3 Migration Guide

This document describes the changes made in v3 of NCronJob and how to migrate from v2.

Version 3 of NCronJob introduces some breaking changes to improve the API.

Second precision is automatically inferred

In v2 one would define as such:

builder.Services.AddNCronJob(
    n => n.AddJob<SimpleJob>(
        p => p.WithCronExpression("* * * * * *", true)));

Inside WithCronExpression, there was an optional parameter that, if set to true, required the cron expression to be in seconds precision. This was a bit confusing and not very intuitive. In v3 the seconds precision is automatically inferred. Therefore, the above code can be simplified to:

builder.Services.AddNCronJob(
    n => n.AddJob<SimpleJob>(
        p => p.WithCronExpression("* * * * * *")));

JobExecutionContext is now IJobExecutionContext

The JobExecutionContext class is no longer used. It has been replaced by the IJobExecutionContext interface. This change was made to allow for easier testing and mocking of the context. Until now you always had to pass in a valid instance which was a bit cumbersome. Now you can mock the interface (or provide a fake) and pass it in.

For the migration, you just have to change the type of the parameter in your job from JobExecutionContext to IJobExecutionContext:

- public Task RunAsync(JobExecutionContext context, CancellationToken token)
+ public Task RunAsync(IJobExecutionContext context, CancellationToken token)

All the public members are still the same as before.