TableAccessLevelInitialService.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Hotline.Caching.Interfaces;
  7. using Hotline.CallCenter.BlackLists;
  8. using Hotline.Settings;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Microsoft.Extensions.Hosting;
  11. using XF.Domain.Cache;
  12. namespace Hotline.Application.Systems
  13. {
  14. public class TableAccessLevelInitialService : BackgroundService
  15. {
  16. private readonly IServiceScopeFactory _serviceScopeFactory;
  17. public TableAccessLevelInitialService(IServiceScopeFactory serviceScopeFactory)
  18. {
  19. _serviceScopeFactory = serviceScopeFactory;
  20. }
  21. /// <summary>
  22. /// This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> starts. The implementation should return a task that represents
  23. /// the lifetime of the long running operation(s) being performed.
  24. /// </summary>
  25. /// <param name="stoppingToken">Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.</param>
  26. /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.</returns>
  27. protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  28. {
  29. using var scope = _serviceScopeFactory.CreateScope();
  30. var cache = scope.ServiceProvider.GetRequiredService<ITableAccessLevelCacheManager>();
  31. cache.Reload();
  32. }
  33. }
  34. }