// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbSeeder dbSeeder) { var defaultCulture = new CultureInfo("es-ec"); defaultCulture.NumberFormat.NumberDecimalSeparator = "."; defaultCulture.NumberFormat.CurrencyDecimalSeparator = "."; //defaultCulture.DateTimeFormat = DateTimeFormatInfo.CurrentInfo; app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture(defaultCulture), SupportedCultures = new List <CultureInfo> { defaultCulture }, SupportedUICultures = new List <CultureInfo> { defaultCulture }, FallBackToParentCultures = false, FallBackToParentUICultures = false, RequestCultureProviders = new List <IRequestCultureProvider> { } }); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } if (!env.IsProduction()) { // Ensure we have the default user added to the store dbSeeder.EnsureSeed().GetAwaiter().GetResult(); } app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); app.UseResponseCaching(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbSeeder dbSeeder) { // We detect if we are doing local development if (env.IsDevelopment()) { // If this is the case then enable more detailed error output app.UseDeveloperExceptionPage(); // Optionally enable browser link integration app.UseBrowserLink(); // Display a more specific error page when an exception occurs connecting to the database app.UseDatabaseErrorPage(); } else { // If this is not the case then forward the error to our generic view app.UseExceptionHandler("/Home/Error"); } // Warning: Do not trigger this seed in your production environment, this is a security risk! if (!env.IsProduction()) { // Ensure we have the default user added to the store dbSeeder.EnsureSeed().GetAwaiter().GetResult(); } // Ensures we can serve static-files that should not be processed by ASP.NET app.UseStaticFiles(); // Enable the authentication middleware so we can protect access to controllers and/or actions app.UseAuthentication(); // We rely on the MVC pipeline to handle our routes //app.UseMvcWithDefaultRoute(); // Enable the reponse caching middleware to serve 200 OK responses directly from cache on sub-sequent requests app.UseResponseCaching(); app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area}/{controller=Start}/{action=Assortment}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Start}/{action=Assortment}/{id?}"); }); }
public static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); try { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var env = services.GetRequiredService <IWebHostEnvironment>(); var context = services.GetRequiredService <ApplicationDbContext>(); Log.Information("Migrating database..."); await context.Database.MigrateAsync(); if (env.IsDevelopment()) { Log.Information("Seeding users and default audios."); var pwHasher = services.GetRequiredService <IPasswordHasher>(); var userId = await ApplicationDbSeeder.UserSeedAsync(context, pwHasher); if (userId > 0) { await ApplicationDbSeeder.AudioSeedAsync(context, userId); } } } await host.RunAsync(); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly."); } finally { Log.CloseAndFlush(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbSeeder dbSeeder, ILoggerFactory loggerFactory) { loggerFactory.AddFile("Logs/HistorialClinico-{Date}.txt"); app.UseMiddleware(typeof(ErrorHandlingMiddleware)); /* * // We detect if we are doing local development * if (env.IsDevelopment()) * { * // If this is the case then enable more detailed error output * app.UseDeveloperExceptionPage(); * * // Optionally enable browser link integration * app.UseBrowserLink(); * * // Display a more specific error page when an exception occurs connecting to the database * app.UseDatabaseErrorPage(); * } * else * {*/ // If this is not the case then forward the error to our generic view //app.UseExceptionHandler("/Home/Error"); //} // Warning: Do not trigger this seed in your production environment, this is a security risk! if (!env.IsProduction()) { // Ensure we have the default user added to the store dbSeeder.EnsureSeed().GetAwaiter().GetResult(); } // Ensures we can serve static-files that should not be processed by ASP.NET app.UseStaticFiles(); // Enable the authentication middleware so we can protect access to controllers and/or actions app.UseAuthentication(); // We rely on the MVC pipeline to handle our routes app.UseMvcWithDefaultRoute(); // Enable the reponse caching middleware to serve 200 OK responses directly from cache on sub-sequent requests app.UseResponseCaching(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { ApplicationDbSeeder.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
private static void SeedShopDb(IWebHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var shopDbContext = services.GetRequiredService <ShopDbContext>(); ApiDbSeeder.Seed(shopDbContext).Wait(); var applicationDbContext = services.GetRequiredService <ApplicationDbContext>(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); ApplicationDbSeeder.Seed(applicationDbContext, roleManager, userManager).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } }
public void Configure(IApplicationBuilder app, ApplicationDbSeeder dbSeeder, ApplicationDbContext dbContext) { if (Scenarios.Plaintext) { app.UsePlainText(); } if (Scenarios.Json) { app.UseJson(); } // Single query endpoints if (Scenarios.DbSingleQueryRaw) { app.UseSingleQueryRaw(); } if (Scenarios.DbSingleQueryDapper) { app.UseSingleQueryDapper(); } if (Scenarios.DbSingleQueryEf) { app.UseSingleQueryEf(); } // Multiple query endpoints if (Scenarios.DbMultiQueryRaw) { app.UseMultipleQueriesRaw(); } if (Scenarios.DbMultiQueryDapper) { app.UseMultipleQueriesDapper(); } if (Scenarios.DbMultiQueryEf) { app.UseMultipleQueriesEf(); } // Multiple update endpoints if (Scenarios.DbMultiUpdateRaw) { app.UseMultipleUpdatesRaw(); } if (Scenarios.DbMultiUpdateDapper) { app.UseMultipleUpdatesDapper(); } if (Scenarios.DbMultiUpdateEf) { app.UseMultipleUpdatesEf(); } // Fortunes endpoints if (Scenarios.DbFortunesRaw) { app.UseFortunesRaw(); } if (Scenarios.DbFortunesDapper) { app.UseFortunesDapper(); } if (Scenarios.DbFortunesEf) { app.UseFortunesEf(); } if (Scenarios.Any("Db")) { dbContext.Database.EnsureCreated(); if (!dbSeeder.Seed()) { Environment.Exit(1); } } if (Scenarios.Any("Mvc")) { app.UseMvc(); } if (Scenarios.StaticFiles) { app.UseStaticFiles(); } app.RunDebugInfoPage(); }
public void Configure(IApplicationBuilder app, ApplicationDbSeeder dbSeeder) { if (Scenarios.Plaintext) { app.UsePlainText(); } if (Scenarios.Json) { app.UseJson(); } if (Scenarios.Copy) { app.UseCopyToAsync(); } // Single query endpoints if (Scenarios.DbSingleQueryRaw) { app.UseSingleQueryRaw(); } if (Scenarios.DbSingleQueryDapper) { app.UseSingleQueryDapper(); } if (Scenarios.DbSingleQueryEf) { app.UseSingleQueryEf(); } // Multiple query endpoints if (Scenarios.DbMultiQueryRaw) { app.UseMultipleQueriesRaw(); } if (Scenarios.DbMultiQueryDapper) { app.UseMultipleQueriesDapper(); } if (Scenarios.DbMultiQueryEf) { app.UseMultipleQueriesEf(); } // Multiple update endpoints if (Scenarios.DbMultiUpdateRaw) { app.UseMultipleUpdatesRaw(); } if (Scenarios.DbMultiUpdateDapper) { app.UseMultipleUpdatesDapper(); } if (Scenarios.DbMultiUpdateEf) { app.UseMultipleUpdatesEf(); } // Fortunes endpoints if (Scenarios.DbFortunesRaw) { app.UseFortunesRaw(); } if (Scenarios.DbFortunesDapper) { app.UseFortunesDapper(); } if (Scenarios.DbFortunesEf) { app.UseFortunesEf(); } if (Scenarios.Any("Db")) { if (!dbSeeder.Seed()) { Environment.Exit(1); } } if (Scenarios.Any("Mvc")) { app.UseMvc(); } if (Scenarios.StaticFiles) { app.UseStaticFiles(); } if (Scenarios.Any("MemoryCachePlaintext")) { app.UseMemoryCachePlaintext(); } if (Scenarios.ResponseCachingPlaintextCached) { app.UseResponseCachingPlaintextCached(); } if (Scenarios.ResponseCachingPlaintextResponseNoCache) { app.UseResponseCachingPlaintextResponseNoCache(); } if (Scenarios.ResponseCachingPlaintextRequestNoCache) { app.UseResponseCachingPlaintextRequestNoCache(); } if (Scenarios.ResponseCachingPlaintextVaryByCached) { app.UseResponseCachingPlaintextVaryByCached(); } app.RunDebugInfoPage(); }