示例#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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint(url: "/swagger/v1/swagger.json", name: "Bmes Api Core");
            });
            app.UseSession();
            app.UseRouting();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            //Create a service scope to get an BmesIdntityDbContext instace using DI
            using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var dbContext   = serviceScope.ServiceProvider.GetService <BmesIdentityDbContext>();
                var roleManager = serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >();
                var userManager = serviceScope.ServiceProvider.GetService <UserManager <User> >();
                //Create the Db if it does not exist and applies any panding migration.
                //dbContext.Database.Migrate();

                IdentityDbSeeder.Seed(dbContext, roleManager, userManager);
            }
        }
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IdentityDbSeeder identityDbSeeder)
        {
            app.UseCors(x => x.AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin());

            app.UseAuthentication();
            app.UseMvc();
            identityDbSeeder.SeedAsync(app.ApplicationServices).Wait();
        }