Exemple #1
0
 private static void InitIdentity(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             var context = services.GetRequiredService <AppDbContext>();
             DbSeed.InitializeAsync(context, services).Wait();
             context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
         }
     }
 }
Exemple #2
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <CustomerInquiryContext>();
                    DbSeed.InitializeAsync(context).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred during initializing the database");
                }
            }
            host.Run();
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            //初始种子数据
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <IExamDbContext>();
                    DbSeed.InitializeAsync(context).Wait();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            host.Run();
        }
Exemple #4
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context  = services.GetRequiredService <CalendarSchedulerContext>();
                    var ucontext = services.GetRequiredService <CalendarUserContext>();
                    await DbSeed.InitializeAsync(context, ucontext, services);
                }
                catch (Exception e)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "an error while seeding DB");
                }
            }
            host.Run();
        }