using Hangfire; using Microsoft.Extensions.Configuration; using System.Reflection; using JiShe.CollectBus.Common.Jobs; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionExtensions { /// /// 添加TcpService服务。 /// public static IServiceCollection AddJobs(this IServiceCollection services, IConfiguration configuration) { var interfaceType = typeof(IBaseJob); var assembly = Assembly.GetExecutingAssembly(); var types = assembly.GetTypes(); foreach (var type in types) { if (type.IsClass && type.GetInterfaces().Contains(interfaceType)) { RecurringJob.AddOrUpdate(type.Name, ()=>((type as IBaseJob)!).Execute(), Cron.Minutely, TimeZoneInfo.Utc); } } return services; } } }