Beispiel #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,
                              RoleManager <UserRoleEntity> roleManager, UserManager <UserEntity> userManager)
        {
            if (env.IsDevelopment())
            {
                //IServiceScopeFactory scopeFactory = app.ApplicationServices
                //    .GetRequiredService<IServiceScopeFactory>();

                //using (IServiceScope scope = scopeFactory.CreateScope())
                //{
                //    RoleManager<UserRoleEntity> roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<UserRoleEntity>>();

                //    // Add test role
                //    AddTestRole(roleManager).Wait();
                //}
                //var roleManager = app.ApplicationServices
                //    .GetRequiredService<RoleManager<UserRoleEntity>>();



                app.UseDeveloperExceptionPage();

                // Lynda Video Tutorial: Part 4 (seed the database with test data)
                // InvalidOperationException is thrown
                // Athletes are currently added in the constructor of the AthleteController
                //var context = app.ApplicationServices.GetRequiredService<FieldScribeAPIContext>();
                //AddTestData(context);
            }

            app.UseHsts(opt =>
            {
                opt.MaxAge(days: 180);
                opt.IncludeSubdomains();
                opt.Preload();
            });


            app.UseAuthentication();

            // Add roles to database
            RolesData.CreateRoles(roleManager).Wait();

            // Add admins and test users to database
            Admins.CreateAdmins(userManager).Wait();
            TestUsers.CreateTestUsers(userManager).Wait();

            app.UseMvc();
        }