using EntrustSettle.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Quartz.Spi;
using System;
namespace EntrustSettle.Extensions
{
///
/// 任务调度 启动服务
///
public static class JobSetup
{
public static void AddJobSetup(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
// 简易版的定时任务
services.AddHostedService();
// Quartz版的定时任务
services.AddSingleton();
services.AddTransient();//Job使用瞬时依赖注入
services.AddSingleton();
//批量注入Quartz版的定时任务
//var baseType = typeof(IJob);
//var pith = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
//var assemblie = Assembly.LoadFrom(Path.Combine(pith, "EntrustSettle.Tasks.dll"));
//var implementTypes = assemblie.GetTypes()
// .Where(t => baseType.IsAssignableFrom(t) && t.IsClass)
// .ToArray();
//foreach (var implementType in implementTypes)
//{
// services.AddTransient(implementType);
//}
}
}
}