You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Tiobon.Core.Common;
|
|
using Tiobon.Core.EventBus;
|
|
using Tiobon.Core.EventBus.EventHandling;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Tiobon.Core.Extensions.HostedService;
|
|
|
|
public class EventBusHostedService : IHostedService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ILogger<EventBusHostedService> _logger;
|
|
|
|
public EventBusHostedService(IServiceProvider serviceProvider, ILogger<EventBusHostedService> logger)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
_logger.LogInformation("Start EventBus Service!");
|
|
await DoWork();
|
|
}
|
|
|
|
private Task DoWork()
|
|
{
|
|
if (AppSettings.app(new string[] { "EventBus", "Enabled" }).ObjToBool())
|
|
{
|
|
var eventBus = _serviceProvider.GetRequiredService<IEventBus>();
|
|
eventBus.Subscribe<TiobonQueryIntegrationEvent, TiobonQueryIntegrationEventHandler>();
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_logger.LogInformation("Stop EventBus Service!");
|
|
return Task.CompletedTask;
|
|
}
|
|
} |