using System.Reflection; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using RdtClient.Data.Data; using RdtClient.Service.Services; using Serilog; namespace RdtClient.Service.BackgroundServices; public class Startup : IHostedService { public static Boolean Ready { get; private set; } private readonly IServiceProvider _serviceProvider; public Startup(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } public async Task StartAsync(CancellationToken cancellationToken) { var version = Assembly.GetEntryAssembly()?.GetName().Version; Log.Warning($"Starting host on version {version}"); using var scope = _serviceProvider.CreateScope(); var dbContext = scope.ServiceProvider.GetRequiredService(); await dbContext.Database.MigrateAsync(cancellationToken); var settings = scope.ServiceProvider.GetRequiredService(); await settings.Seed(); await settings.ResetCache(); Ready = true; } public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; }