Пример #1
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var env      = services.GetService <IWebHostEnvironment>().IsDevelopment();
                var context  = services.GetRequiredService <ApplicationDbContext>();

                ApplicationDbInitializer.Initializer(context, env);
            }
            host.Run();
        }
Пример #2
0
 private static void CreateDbIfNotExists(IHost host)
 {
     using (IServiceScope scope = host.Services.CreateScope())
     {
         IServiceProvider services = scope.ServiceProvider;
         try
         {
             ApplicationDbContext db = services.GetRequiredService <ApplicationDbContext>();
             ApplicationDbInitializer.Initializer(db);
         }
         catch (Exception e)
         {
             ILogger logger = services.GetRequiredService <ILogger <Program> >();
             logger.LogError(e, "An error occurred creating the DB.");
         }
     }
 }