JiShe.CollectBus/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2024-11-13 17:50:52 +08:00
using System.Collections.Generic;
using System.Reflection;
2024-11-13 00:30:24 +08:00
using Hangfire;
using JiShe.CollectBus.Common.Jobs;
2024-11-13 17:50:52 +08:00
using JiShe.CollectBus.MQ.Sender;
using MassTransit;
2024-11-12 18:18:43 +08:00
using Microsoft.Extensions.DependencyInjection;
2024-11-13 00:30:24 +08:00
using Volo.Abp;
using Volo.Abp.Modularity;
2024-11-12 18:18:43 +08:00
namespace JiShe.CollectBus.Application
{
2024-11-13 17:50:52 +08:00
[DependsOn(typeof(JiSheCollectBusMqSenderModule))]
2024-11-13 00:30:24 +08:00
public class JiSheCollectBusApplicationModule: AbpModule
2024-11-12 18:18:43 +08:00
{
2024-11-13 00:30:24 +08:00
public override void ConfigureServices(ServiceConfigurationContext context)
2024-11-12 18:18:43 +08:00
{
2024-11-13 17:50:52 +08:00
context.Services.AddSingleton<ISendEndpointProvider>();
2024-11-13 00:30:24 +08:00
//var configuration = context.Services.GetConfiguration();
//context.Services.AddJobs(configuration);
}
public override void OnPostApplicationInitialization(ApplicationInitializationContext context)
{
var interfaceType = typeof(IBaseJob);
var assembly = Assembly.GetExecutingAssembly();
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsClass && type.GetInterfaces().Contains(interfaceType))
{
var instance = context.ServiceProvider.GetService(type);
//var instance = services.GetObject<IBaseJob>();
//var instance = Activator.CreateInstance(type);
RecurringJob.AddOrUpdate(type.Name, () => type.GetMethod("Execute").Invoke(instance, null), Cron.Minutely);
}
}
2024-11-12 18:18:43 +08:00
}
}
}