Selector/Selector.Web/Services/EventHubMappingService.cs

45 lines
1.2 KiB
C#
Raw Normal View History

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;
using Selector.Events;
2021-11-03 22:27:50 +00:00
namespace Selector.Web.Service
{
public class EventHubMappingService: IHostedService
2021-11-03 22:27:50 +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
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)
{
Logger.LogInformation("Starting hub event mapping service");
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;
}
}
}