public static void Main(string[] args)
        {
            IWebHost host = CreateWebHostBuilder(args).Build();

            // Initializes db.
            using (IServiceScope scope = host.Services.CreateScope())
            {
                IServiceProvider services = scope.ServiceProvider;
                try
                {
                    OrderDBContext   context       = services.GetRequiredService <OrderDBContext>();
                    ISeedDataService dbInitializer = services.GetRequiredService <ISeedDataService>();
                    dbInitializer.Initialize(context).GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    ILogger <Program> logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              IAdminSettingService adminService,
                              ISeedDataService seedDataService,
                              SpojDebugDbContext dbContext)
        {
            dbContext.Database.Migrate();

            app.UseHangfireDashboard();
            app.UseHangfireServer();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

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

            seedDataService.InitData();
            AppStartBackGroundJob(adminService, monitor);
        }
        public async Task Invoke(HttpContext context, ISeedDataService seedDataService)
        {
            await seedDataService.EnsureSeedData();

            await _next.Invoke(context);
        }
 public SeedDataController(ISeedDataService seedDataService)
 {
     _seedDataService = seedDataService;
 }