Selector/Selector.Web/Services/CacheHubProxyService.cs

49 lines
1.4 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;
namespace Selector.Web.Service
{
public class CacheHubProxyService: IHostedService
{
private readonly ILogger<CacheHubProxyService> Logger;
private readonly CacheHubProxy Proxy;
2021-11-05 07:58:48 +00:00
private readonly IServiceScopeFactory ScopeFactory;
2021-11-03 22:27:50 +00:00
public CacheHubProxyService(
ILogger<CacheHubProxyService> logger,
2021-11-05 07:58:48 +00:00
CacheHubProxy proxy,
IServiceScopeFactory scopeFactory
2021-11-03 22:27:50 +00:00
)
{
Logger = logger;
Proxy = proxy;
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 cache hub proxy");
2021-11-05 07:58:48 +00:00
using(var scope = ScopeFactory.CreateScope())
{
foreach(var mapping in scope.ServiceProvider.GetServices<IUserMapping>())
{
mapping.FormAll();
}
}
2021-11-03 22:27:50 +00:00
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
Logger.LogInformation("Stopping cache hub proxy");
return Task.CompletedTask;
}
}
}