// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ProductDbInitializer seeder, ProductIdentityInitializer identitySeeder, ILoggerFactory loggerFactory) { #region Logger loggerFactory.AddConsole(_config.GetSection("Logging")); loggerFactory.AddDebug(); #endregion if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseIdentity(); app.UseMvc().UseAuthentication(); #region CORS Commented Out //app.UseCors(cfg => //{ // cfg.AllowAnyHeader() // .AllowAnyMethod() // .AllowAnyOrigin(); // //.WithOrigins("http://hurriyet.com.tr") <- This tells anyone can access from hurriyet.com.tr to my API. //}); #endregion seeder.Seed().Wait(); //identitySeeder.Seed().Wait(); // Comment this after first initial seed. }
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 <ProductContext>(); ProductDbInitializer.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured while initializing the database"); } } host.Run(); }
/// <summary> /// Initialize DB entries at the very first time if DB is blank. /// </summary> public void DbInitialize() { ProductDbInitializer.Initialize(Context); }