mirror of
https://github.com/fergalmoran/SilkierQuartz.git
synced 2025-12-22 09:37:56 +00:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
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<NameValueCollection> stdSchedulerFactoryOptions)
|
|
{
|
|
services.AddHostedService<QuartzHostedService>();
|
|
|
|
services.AddTransient<ISchedulerFactory>(provider =>
|
|
{
|
|
var options = new NameValueCollection();
|
|
stdSchedulerFactoryOptions?.Invoke(options);
|
|
var result = new StdSchedulerFactory();
|
|
if (options.Count > 0)
|
|
result.Initialize(options);
|
|
return new StdSchedulerFactory();
|
|
});
|
|
services.AddTransient<IJobFactory, ServiceCollectionJobFactory>();
|
|
|
|
return new JobRegistrator(services);
|
|
}
|
|
}
|
|
}
|