using Microsoft.EntityFrameworkCore; namespace Vegasco.WebApi.Persistence; public class ApplyMigrationsService(ILogger logger, IServiceScopeFactory scopeFactory) : IHostedService { public async Task StartAsync(CancellationToken cancellationToken) { logger.LogInformation("Starting migrations"); using IServiceScope scope = scopeFactory.CreateScope(); await using var dbContext = scope.ServiceProvider.GetRequiredService(); await dbContext.Database.MigrateAsync(cancellationToken); } public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; }