// 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(); }
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(); }
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(); }
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); }
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(); }
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(); }
// 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(); }
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(); }
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(); }
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(); }
// 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(); }