private async Task SeedDataAsync()
 {
     var context  = _scope.ServiceProvider.GetService <SqliteContext>();
     var service  = _scope.ServiceProvider.GetService <IDungeonService>();
     var seedData = new ContextSeedData(service, context);
     await seedData.SeedDataAsync();
 }
Example #2
0
 public void Configure(IApplicationBuilder app, IHostEnvironment env, ContextSeedData seedData)
 {
     app.ConfigureDB(Configuration);
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
         seedData.SeedDataAsync().Wait();
     }
     else
     {
         seedData.SeedBaseAsync().Wait();
         app.UseExceptionHandler("/Home/Error");
         app.UseHsts();
     }
     app.UseHttpsRedirection();
     app.UseStaticFiles();
     app.UseRouting();
     app.UseCookiePolicy();
     app.UseAuthentication();
     app.UseAuthorization();
     app.UseEndpoints(endpoints =>
     {
         endpoints.MapControllerRoute(
             name: "default",
             pattern: "{controller=Home}/{action=Index}/{id?}");
     });
 }
Example #3
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

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

                try
                {
                    var context = services.GetRequiredService <ApplicationDbContext>();
                    ContextSeedData.ensureSeedData(services).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }
        // 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, ContextSeedData seeder)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();

            app.UseIdentity();

            Mapper.Initialize(config =>
            {
                config.CreateMap <PackageViewModel, Package>().ReverseMap();
                config.CreateMap <StopViewModel, Stop>().ReverseMap();
            });

            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "App", action = "Index" }
                    );
            });

            //seeder.EnsureSeedData().Wait();
        }
Example #5
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, ContextSeedData seeder)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

            Mapper.Initialize(config =>
            {
                config.CreateMap <ProjectViewModel, Project>();
                config.CreateMap <Project, ProjectViewModel>();
            });

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

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseIdentity();

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

            seeder.EnsureSeedData().Wait();
        }