| #region << 版 本 注 释 >> | 
| /*---------------------------------------------------------------- | 
|  * 命名空间:WIDESEAWCS_QuartzJob | 
|  * 创建者:胡童庆 | 
|  * 创建时间:2024/8/2 16:13:36 | 
|  * 版本:V1.0.0 | 
|  * 描述:调度服务注入 | 
|  * | 
|  * ---------------------------------------------------------------- | 
|  * 修改人: | 
|  * 修改时间: | 
|  * 版本:V1.0.1 | 
|  * 修改说明: | 
|  *  | 
|  *----------------------------------------------------------------*/ | 
| #endregion << 版 本 注 释 >> | 
|   | 
| using Microsoft.Extensions.DependencyInjection; | 
| using Quartz.Spi; | 
| using Quartz; | 
| using System; | 
| using System.Collections.Generic; | 
| using System.Linq; | 
| using System.Reflection; | 
| using System.Text; | 
| using System.Threading.Tasks; | 
|   | 
| namespace WIDESEAWCS_QuartzJob.QuartzExtensions | 
| { | 
|     /// <summary> | 
|     /// 调度服务注入 | 
|     /// </summary> | 
|     public static class JobSetup | 
|     { | 
|         public static void AddJobSetup(this IServiceCollection services) | 
|         { | 
|             if (services == null) throw new ArgumentNullException(nameof(services)); | 
|   | 
|             services.AddSingleton<IJobFactory, JobFactory>(); | 
|             services.AddSingleton<ISchedulerCenter, SchedulerCenterServer>(); | 
|             //任务注入 | 
|             var baseType = typeof(IJob); | 
|             var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; | 
|             var referencedAssemblies = System.IO.Directory.GetFiles(path, "WIDESEAWCS_Tasks.dll").Select(Assembly.LoadFrom).ToArray(); | 
|             var types = referencedAssemblies | 
|                 .SelectMany(a => a.DefinedTypes) | 
|                 .Select(type => type.AsType()) | 
|                 .Where(x => x != baseType && baseType.IsAssignableFrom(x)).ToArray(); | 
|             var implementTypes = types.Where(x => x.IsClass).ToArray(); | 
|             foreach (var implementType in implementTypes) | 
|             { | 
|                 services.AddTransient(implementType); | 
|             } | 
|         } | 
|     } | 
| } |