예제 #1
0
        private async static Task InitContext(IHost host)
        {
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var dbContext     = services.GetRequiredService <AppDBContext>();
                var roleManager   = services.GetRequiredService <RoleManager <IdentityRole <int> > >();
                var userManager   = services.GetRequiredService <UserManager <User> >();
                var configuration = services.GetRequiredService <IConfiguration>();

                await AppDBContextInit.InitDbContext(dbContext);

                await AppDBContextInit.InitRoles(roleManager);

                await AppDBContextInit.InitUsers(userManager, configuration);
            }

            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occured during migration");
            }
        }