示例#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, DbInitilizer dbInitializer)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/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();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
            dbInitializer.Seed();
        }
示例#2
0
        public static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("hosting.json", optional: false, reloadOnChange: true)
                         .Build();

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseConfiguration(config)
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

            host.Run();

            using (var scope = host.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <DataContext>();
                context.Database.Migrate();
                DbInitilizer.SeedData(context);
            }

            host.Run();
        }
示例#3
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <DbContext>();
                context.Database.Migrate();
                DbInitilizer.SeedData(context);
            }
            host.Run();
        }
示例#4
0
        public static IApplicationBuilder MigrateDb(this IApplicationBuilder app, DatabaseSettings dbSettings)
        {
            if (dbSettings == null)
            {
                throw new ArgumentNullException(nameof(dbSettings));
            }

            if (dbSettings.MigrateOnStartup)
            {
                DbInitilizer.Migrate(app.ApplicationServices);
            }

            return(app);
        }
示例#5
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <AppDbContext>();
                    DbInitilizer.seed(context);
                }catch (Exception ex)
                {
                    throw ex;
                }
            }
            host.Run();
        }
示例#6
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <ApplicationDbContext>();
                    DbInitilizer.InitilizeAsync(context, services).Wait();
                }catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "Error while seeding");
                }
            }
            host.Run();
        }
示例#7
0
        // Defines the method used to link the correct dbcontext to the program
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <EventsPlusContext>();
                    DbInitilizer.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured creating the DB");
                }
            }
            host.Run();
        }
示例#8
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <ClienteContext>();
                    DbInitilizer.Initilize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "Um erro ocorreu no método seeding do contexto.");
                }
            }

            host.Run();
        }
示例#9
0
文件: Program.cs 项目: MetiH/Project
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <AppDbContext>();
                    DbInitilizer.Been(context);
                }
                catch (Exception)
                {
                    //we could log this in a real-world situation
                }
            }

            host.Run();
            // BuildWebHost(args).Run();
        }
示例#10
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);


            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = scope.ServiceProvider.GetRequiredService <DataContext>();
                    DbInitilizer.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error orrured seeding the DB.");
                }
            }
            host.Run();
        }
示例#11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            using (var scopeservice =
                       app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var context = scopeservice.ServiceProvider.GetService <ApplicationDbContext>();
                DbInitilizer.Initialize(context);
            }
            ScopeRead = Configuration["AzureAdB2C:ScopeRead"];
            app.UseHttpsRedirection();
            app.UseAuthentication();

            app.UseMvc();
        }