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

            // Seed Database on Startup :
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                DbSeed.Initialize(services).Wait();
            }

            host.Run();
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env, ApplicationDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            app.UseAuthentication();
            app.UseMvc();
            DbSeed.Initialize(dbContext);
            dbContext.Database.EnsureCreated();
        }
示例#3
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <Inlämningsuppgift_1_aspContext>();
                context.RemoveRange();
                context.SaveChanges();
                DbSeed.Initialize(context);
            }

            host.Run();
        }
示例#4
0
文件: Program.cs 项目: nd1226/EFcore
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <SchoolContext>();
                    DbSeed.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }
示例#5
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>();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    DbSeed.Initialize(context, roleManager, userManager);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }