예제 #1
0
 private void Seed(IApplicationBuilder app)
 {
     using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
     {
         var context     = scope.ServiceProvider.GetService <BringItAuthDbContext>();
         var userManager = scope.ServiceProvider.GetService <UserManager <ApplicationUser> >();
         var roleManager = scope.ServiceProvider.GetService <RoleManager <IdentityRole> >();
         context.Database.Migrate();
         SeedDbContext.Seed(context, userManager, roleManager).Wait();
     }
 }
예제 #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // Database Migrations
            using (var serviceScope = app.ApplicationServices.CreateScope())
            {
                var dbContext = serviceScope.ServiceProvider.GetRequiredService <TaskApiDbContext>();

                if (env.IsDevelopment())
                {
                    dbContext.Database.Migrate();
                }

                SeedDbContext.SeedData(dbContext);
            }

            if (env.IsDevelopment())
            {
                app.UseExceptionHandler(application =>
                {
                    application.Run(async context =>
                    {
                        context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                        context.Response.ContentType = "application/json";

                        var ex = context.Features.Get <IExceptionHandlerFeature>();
                        if (ex != null)
                        {
                            await context.Response
                            .WriteAsync(JsonConvert.SerializeObject(new { ex.Error?.Message, ex.Error?.StackTrace }))
                            .ConfigureAwait(continueOnCapturedContext: false);
                        }
                    });
                });
            }
            else
            {
                app.UseHsts();
            }

            app.UseCors("MyPolicy");
            app.UseHttpsRedirection();
            app.UseMvc(routes => routes.MapRoute("default", "api/{controller}/{action}/{id?}"));
        }
예제 #3
0
 public HomeController(SeedDbContext db)
 {
     _db = db;
 }