This commit is contained in:
cjd
2025-11-04 21:09:16 +08:00
parent 8260e293c7
commit bb90a020dc
592 changed files with 61749 additions and 27 deletions

View File

@@ -0,0 +1,45 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using DouyinApi.Common;
using DouyinApi.EventBus;
using DouyinApi.EventBus.EventHandling;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace DouyinApi.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<BlogQueryIntegrationEvent, BlogQueryIntegrationEventHandler>();
}
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Stop EventBus Service!");
return Task.CompletedTask;
}
}