2021-11-03 22:27:50 +00:00
|
|
|
using System;
|
2021-11-05 07:58:48 +00:00
|
|
|
using System.Collections.Generic;
|
2021-11-03 22:27:50 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2021-11-05 07:58:48 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-11-03 22:27:50 +00:00
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
2021-12-19 18:44:03 +00:00
|
|
|
using Selector.Events;
|
|
|
|
|
2021-11-03 22:27:50 +00:00
|
|
|
namespace Selector.Web.Service
|
|
|
|
{
|
2021-12-19 18:44:03 +00:00
|
|
|
public class EventHubMappingService: IHostedService
|
2021-11-03 22:27:50 +00:00
|
|
|
{
|
2021-12-19 18:44:03 +00:00
|
|
|
private readonly ILogger<EventHubMappingService> Logger;
|
2021-11-05 07:58:48 +00:00
|
|
|
private readonly IServiceScopeFactory ScopeFactory;
|
2021-11-03 22:27:50 +00:00
|
|
|
|
2021-12-19 18:44:03 +00:00
|
|
|
public EventHubMappingService(
|
|
|
|
ILogger<EventHubMappingService> logger,
|
2021-11-05 07:58:48 +00:00
|
|
|
IServiceScopeFactory scopeFactory
|
2021-11-03 22:27:50 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
Logger = logger;
|
2021-11-05 07:58:48 +00:00
|
|
|
ScopeFactory = scopeFactory;
|
2021-11-03 22:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
2021-12-19 18:44:03 +00:00
|
|
|
Logger.LogInformation("Starting hub event mapping service");
|
2021-12-19 13:44:22 +00:00
|
|
|
|
|
|
|
using (var scope = ScopeFactory.CreateScope())
|
|
|
|
{
|
|
|
|
var hubProxy = scope.ServiceProvider.GetRequiredService<EventHubProxy>();
|
|
|
|
hubProxy.FormMappings();
|
2021-11-05 07:58:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 22:27:50 +00:00
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|