Example #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IPrivilegeService privilegeService, IRoleService roleService,
                              IUserService userService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            app.UseStatusCodePagesWithReExecute("/Home/StatusCodePage", "?code={0}");

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            PrivilegeInitializer.SeedData(privilegeService);
            RoleInitializer.SeedData(privilegeService, roleService);
            UserInitializer.SeedData(userService, roleService);

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id:int?}");
            });
        }
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     using (var scope = _serviceProvider.CreateScope())
     {
         var seeder = new UserInitializer();
         await seeder.SeedData(
             scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(),
             scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(),
             scope.ServiceProvider.GetRequiredService <ApplicationDbContext>());
     }
 }