コード例 #1
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 <UserContext>();
                    var context2 = services.GetRequiredService <VariableContext>();
                    var context3 = services.GetRequiredService <EventContext>();

                    context.Database.Migrate();
                    context2.Database.Migrate();
                    context3.Database.Migrate();

                    UserSeed.Initialize(services);
                    VariableSeed.Initialize(services);
                    EventSeed.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;

                try
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    //
                    //                    StateSeed.Initialize(services);
                    RoleSeed.Initialize(services, logger).Wait();
                    UserSeed.Initialize(services, logger).Wait();

                    EmployeeCvSeed.Initialize(services, logger).Wait();
                    EmployeeCvExternalMaterialSeed.Initialize(services, logger).Wait();
                    EmployeeCvJobHisotriesSeed.Initialize(services, logger).Wait();
                    EmployeeCvSkillSeed.Initialize(services, logger).Wait();
                    EmployeeCvWorkDaySeed.Initialize(services, logger).Wait();

                    EmployerJobProfileSeed.Initialize(services, logger).Wait();
                    EmployerJobSkillSeed.Initialize(services, logger).Wait();
                }
                catch (Exception ex) {
                    services.GetRequiredService <ILogger <Program> >().LogError(ex, "An error occurred while seeding the database");
                    throw;
                }
            }
            host.Run();
//            BuildWebHost(args).Run();
        }