using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; namespace CMSMicroservice.Infrastructure.Persistence; public class ApplicationDbContextInitialiser { private readonly ApplicationDbContext _context; private readonly ILogger _logger; public ApplicationDbContextInitialiser(ApplicationDbContext context, ILogger logger) { _context = context; _logger = logger; } public async Task InitialiseAsync() { try { if (_context.Database.IsSqlServer()) { await _context.Database.MigrateAsync(); } } catch (Exception ex) { _logger.LogError(ex, "An error occurred while initialising the database."); throw; } } public async Task SeedAsync() { try { await TrySeedAsync(); } catch (Exception ex) { _logger.LogError(ex, "An error occurred while seeding the database."); throw; } } public async Task TrySeedAsync() { } }