Example #1
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;
                try {
                    var context = services.GetRequiredService <AccountDbContext>();
                    AccountDbInitializer.Initialize(context);
                } catch (Exception ex) {
                    var logger = services.GetRequiredService <ILogger <Program> > ();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
Example #2
0
        public static async Task Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context     = services.GetRequiredService <AccountDbContext>();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();

                    var dbInitializerLogger = services.GetRequiredService <ILogger <AccountDbInitializer> >();
                    await AccountDbInitializer.Initialize(context, userManager, roleManager, dbInitializerLogger).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the AccountDb database.");
                }
                try
                {
                    var context = services.GetRequiredService <ApplicationDbContext>();
                    await ApplicationDbInitializer.Initialize(context).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the ApplicationDb database.");
                }
                try
                {
                    var contextOptions = services.GetRequiredService <DbContextOptions <HangfireDbContext> >();
                    await HangfireDbInitializer.InitializeAsync(contextOptions).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the HangfireDb database.");
                }
            }

            host.Run();
        }
Example #3
0
        public static void Main(string[] args)
        {
            IHost host = CreateHostBuilder(args).Build();

            using (IServiceScope scope = host.Services.CreateScope())
            {
                // Get service provider
                IServiceProvider services = scope.ServiceProvider;

                // Get database and migrate
                CreativeFusionsDbContext dbContext = services.GetRequiredService <CreativeFusionsDbContext>();
                dbContext.Database.Migrate();

                // Seed database with test data
                AccountDbInitializer.SeedDatabase(services);
            }
            host.Run();
        }
Example #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();

                // Browser Link is not compatible with Kestrel 1.1.0
                // For details on enabling Browser Link, see https://go.microsoft.com/fwlink/?linkid=840936
                // app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseSession();

            app.UseStaticFiles();

            app.UseIdentity();

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            MdmDbInitializer.InitializeAsync(app.ApplicationServices).Wait();
            AccountDbInitializer.InitializeAsync(app.ApplicationServices).Wait();
        }