/// <summary> /// Adds <see cref="SchedulerHostedService"/> service with ability to register all of the cron job inside the context with /// global error handler <see cref="UnobservedTaskExceptionEventArgs"/>. /// </summary> /// <param name="services"></param> /// <param name="config"></param> /// <returns></returns> public static IServiceCollection AddScheduler(this IServiceCollection services, Action <SchedulerBuilder> config) { var builder = new SchedulerBuilder(services); config(builder); CreateInstance(builder.Services, builder.UnobservedTaskExceptionHandler); return(builder.Services); }
/// <summary> /// Adds <see cref="IScheduledJob"/> job to DI without support for <see cref="UnobservedTaskExceptionEventArgs"/> delegate. /// </summary> /// <typeparam name="TJob"></typeparam> /// <typeparam name="TJobOptions"></typeparam> /// <param name="services"></param> /// <param name="sectionName"></param> /// <returns></returns> public static IServiceCollection AddSchedulerJob <TJob, TJobOptions>( this IServiceCollection services, string sectionName = "SchedulerJobs") where TJob : class, IScheduledJob where TJobOptions : SchedulerOptions, new() { var builder = new SchedulerBuilder(services); // add job with configuration settings builder.AddJob <TJob, TJobOptions>(sectionName); CreateInstance(builder.Services); return(builder.Services); }