Пример #1
0
        public static void Main(string[] args)
        {
            // create the WebHost object
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                // get the service providers
                var services = scope.ServiceProvider;
                try
                {
                    var serviceProvider = services.GetRequiredService <IServiceProvider>();
                    // get the Config object for the appsettings.json file
                    var configuration = services.GetRequiredService <IConfiguration>();
                    // pass the service proiders and the config object to CreateRoles()
                    SeedRoles.CreateRoles(serviceProvider, configuration).Wait();
                }
                catch (Exception exception)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(exception, "An error occurred while creating roles");
                }
            }

            // start the web app
            host.Run();
        }
Пример #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context, RoleManager <StoreRole> roleManager, UserManager <SneakerSeekerUser> userManager)
        {
            StripeConfiguration.SetApiKey(Configuration["Stripe:TestSecretKey"]);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

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

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

            SeedRoles.CreateRoles(context, userManager, roleManager).Wait();
        }
Пример #3
0
        public static void Main(string[] args)
        {
            // Create the WebHost object
            var host = CreateHostBuilder(args).Build();

            // Invoke the SeedRoles.CreateRoles() here
            using (var scope = host.Services.CreateScope())
            {
                // Get the ServiceProvider
                var services = scope.ServiceProvider;
                try
                {
                    // Bind the ServiceProvider and the Configuration(appsetting.json)
                    var serviceProvider = services.GetRequiredService <IServiceProvider>();
                    var configuration   = services.GetRequiredService <IConfiguration>();

                    // Pass the ServiceProvider and the Configuration object to CreateRoles()
                    SeedRoles.CreateRoles(serviceProvider, configuration).Wait();
                }
                catch (Exception exception)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(exception, "Error - Creating Roles");
                }
            }

            // Start the Web Application
            host.Run();
        }
Пример #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

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

            app.UseRouting();
            DatabaseInitializer.Seed(app);

            app.UseSession();
            app.UseAuthentication();

            app.UseAuthorization();

            SeedRoles.CreateRoles(serviceProvider, Configuration).Wait();


            //app.UseEndpoints(endpoints =>
            //{
            //    endpoints.MapRazorPages();
            //});

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapRazorPages();
            });
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            DbInitializer.Seed(app);

            app.UseSession();
            app.UseAuthentication();
            app.UseMvcWithDefaultRoute();

            SeedRoles.CreateRoles(serviceProvider, Configuration).Wait();
        }
Пример #6
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var serviceProvider = services.GetRequiredService <IServiceProvider>();
                    SeedRoles.CreateRoles(serviceProvider).Wait();
                }
                catch (Exception exception)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(exception, "Unable to create and asign new roles.");
                }
            }

            host.Run();
        }
Пример #7
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var serviceProvider = services.GetRequiredService <IServiceProvider>();
                    var configuration   = services.GetRequiredService <IConfiguration>();
                    SeedRoles.CreateRoles(serviceProvider, configuration).Wait();
                }
                catch (Exception exception)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(exception, "An error occurred while creating roles");
                }
            }

            host.Run();
        }