Innofactor.QuartzAspNet by Innofactor

<PackageReference Include="Innofactor.QuartzAspNet" Version="1.14.0" />

 QuartzExtensions

public static class QuartzExtensions
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Quartz; using Quartz.Impl; using Quartz.Spi; using System; using System.Collections.Specialized; using System.Linq; using System.Threading; namespace Innofactor.QuartzAspNet { public static class QuartzExtensions { public static void UseQuartz(this IServiceCollection services, params Type[] jobs) { services.AddSingleton<IJobFactory, BatchJobFactory>(); services.Add(from jobType in jobs select new ServiceDescriptor(jobType, jobType, ServiceLifetime.Transient)); services.AddSingleton(delegate(IServiceProvider provider) { NameValueCollection nameValueCollection = new NameValueCollection { { "quartz.serializer.type", "json" } }; StdSchedulerFactory val = new StdSchedulerFactory(nameValueCollection); IScheduler result = val.GetScheduler(default(CancellationToken)).Result; result.set_JobFactory(provider.GetService<IJobFactory>()); result.Clear(default(CancellationToken)); result.Start(default(CancellationToken)); return result; }); } public static void StartJob<TJob>(this IScheduler scheduler, ITrigger trigger) where TJob : IJob { string name = typeof(TJob).Name; IJobDetail val = JobBuilder.Create<TJob>().WithIdentity(name).Build(); scheduler.ScheduleJob(val, trigger, default(CancellationToken)); } } }