using Microsoft.Extensions.DependencyInjection; using Quartz; using Quartz.Impl; using Quartz.Spi; using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; namespace QuartzHostedService { public static class IServiceCollectionExtensions { public static IJobRegistrator UseQuartzHostedService(this IServiceCollection services, Action stdSchedulerFactoryOptions) { services.AddHostedService(); services.AddTransient(provider => { var options = new NameValueCollection(); stdSchedulerFactoryOptions?.Invoke(options); var result = new StdSchedulerFactory(); if (options.Count > 0) result.Initialize(options); return new StdSchedulerFactory(); }); services.AddTransient(); return new JobRegistrator(services); } } }