// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug( ); app.UseMvc( ); MoviesInitializer.Initialize(app.ApplicationServices); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { try { var dbContext = scope.ServiceProvider.GetService <MoviesContext>(); dbContext.Database.EnsureCreated(); MoviesInitializer.Initialize(dbContext); } catch (Exception e) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "An error occured while initializing the database."); } } host.Run(); }