コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            //if (env.IsDevelopment())
            //{
            app.UseDeveloperExceptionPage();
            app.UseBrowserLink();
            //}
            //else
            //{
            //    app.UseExceptionHandler("/Home/Error");
            //}

            app.UseStaticFiles();

            app.UseAuthentication();

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

            IServiceScopeFactory scopeFactory = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>();

            using (IServiceScope scope = scopeFactory.CreateScope())
            {
                var profilesRepository = scope.ServiceProvider.GetRequiredService <IProfilesRepository>();
                ProfilesSeed.Seed(profilesRepository);

                var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();

                var usersSeed = new UsersSeed(profilesRepository);
                usersSeed.Seed(userManager).Wait();

                RolesSeed.Seed(roleManager).Wait();
                UserRolesSeed.Seed(userManager).Wait();
            }
        }