namespace Brizco.Identity.Api.Services; public class DbInitializerService : IDbInitializerService { private readonly ApplicationContext _context; private readonly ILogger _logger; public DbInitializerService( ApplicationContext context, ILogger logger) { _context = context; _logger = logger; } public void Initialize() { try { _context.Database.Migrate(); _logger.LogInformation("Migration SUCCESS !!!!"); } catch (Exception e) { _logger.LogError(e, e.Message); } } public static void InitilizeDB(IApplicationBuilder app) { var scopeFactory = app.ApplicationServices.GetRequiredService(); using (var scope = scopeFactory.CreateScope()) { var identityDbInitialize = scope.ServiceProvider.GetService(); if (identityDbInitialize != null) { identityDbInitialize.Initialize(); } } } }