NCronJob-Dev/NCronJob

Passed in Parameter are not immutable and can effect other job runs

Closed this issue · 0 comments

When registering a job with a complex parameter:

public class MyParameter
{
  public int Counter { get; set; }
}

Services.AddNCronJob(b =>
{
  b.AddJob<MyJob>().WithCronExpression(...);
});

public class MyJob : IJob
{
  public Task RunAsync(JobExecutionContext context, CancellationToken token)
  {
     var myParam = (MyParameter)context.Parameter;
     myParam.Counter++; // This will be incremented with each job run
  }
}

The state is passed on to the next run - the question is whether or not we want to prohibit that or just want to highlight this in our documentation.