コード例 #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, UserManager <IdentityUser> userManager,
                              RoleManager <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

                #pragma warning disable CS0618 // Type Or Member Is Obsolete
                app.UseDatabaseErrorPage();
                #pragma warning restore CS0618 // Type Or Member Is Obsolete
            }
            else
            {
                app.UseExceptionHandler("/error");
                app.UseHsts(); // The Default HSTS Value Is 30 Days. You May Want To Change This For Production Scenarios. (https://aka.ms/aspnetcore-hsts)
            }

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Book Store API");
                options.RoutePrefix = string.Empty;
            });

            app.UseHttpsRedirection();

            app.UseCors("CorsPolicy");

            SeedData.Seed(roleManager, userManager).Wait();

            app.UseRouting();

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

            app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
        }
コード例 #2
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            //
            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context = services.GetRequiredService <StoreContext>();
                    await context.Database.MigrateAsync();

                    await SeedData.SeedDataAsync(context, loggerFactory);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred during migration");
                }
            }
            await host.RunAsync();
        }
コード例 #3
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var context     = services.GetRequiredService <DataContext>();
                var userManager = services.GetRequiredService <UserManager <AppUser> >();
                var roleManager = services.GetRequiredService <RoleManager <AppRole> >();

                await context.Database.MigrateAsync();

                await SeedData.SeedUsers(userManager, roleManager);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error has occured during migration !!");
            }
            await host.RunAsync();
        }