Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var webHostcArgs = args.Where(arg => arg != "/opt/startup/init_container.sh").ToArray();
            var host         = BuildWebHost(webHostcArgs);


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

                try
                {
                    var context = services.GetRequiredService <QOTDContext>();
                    context.Database.Migrate();
                    // seeding intitial values for Question of the Day Featureset
                    SeedParticipants.Initialize(services);
                    SeedDataQOTD.InitializeQOTD(services);
                    SeedAnswers.InitializeAsync(services).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                //get the config to access local datasecrets
                var SecretsConfig = services.GetService <IConfiguration>();

                try
                {
                    var context     = services.GetRequiredService <ApplicationDbContext>();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();

                    var dbInitializerLogger           = services.GetRequiredService <ILogger <DbInitializer> >();
                    Dictionary <string, string> users = new Dictionary <string, string>()
                    {
                        { "user1name", SecretsConfig["user1name"] },
                        { "user2name", SecretsConfig["user2name"] },
                        { "user1pass", SecretsConfig["user1pass"] },
                        { "user2pass", SecretsConfig["user2pass"] },
                    };
                    DbInitializer.Initialize(context, users, userManager, roleManager, dbInitializerLogger).Wait();
                    SeedDataQOTD.InitializeQOTD(services);
                    SeedParticipants.Initialize(services);
                    SeedAnswers.InitializeAnswers(services);
                    SeedHardZones.InitializeData(services);
                    SeedDataHomeSales.InitializeHomeSales(services);
                    SeedDataHomeListings.InitializeHomeListings(services);
                    SeedWAQuotes.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while migrating the database.");
                }
            }

            host.Run();
        }