public static void Seed(this ApplicationDbContext context, IWebHost host) { if (context.AllMigrationsApplied()) { var seed = new SeedDbData(host, context); } }
public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <ServerOptions> serverOptions, SeedDbData seeder) { // When in development if (env.IsDevelopment()) { // Log in Debug Window and in Console using the minimum log level from options loggerFactory.AddDebug(serverOptions.Value.LogLevel); loggerFactory.AddConsole(serverOptions.Value.LogLevel); // Use developer exception pages app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } // When in staging/production else { // Log in files (using the Serilog library) using the minimum log level from options AwesomeMethods.CreateSerilogLogger(env, serverOptions.Value.LogLevel); loggerFactory.AddSerilog(); // Use custom exception page app.UseExceptionHandler("/Home/Error"); } // Add custom middlware to log exceptions and fall back to the previous exception handlers app.UseLogExceptionHandler(); // Configure the localization. en-US and el-GR cultures are supported with en-US being // the default one ConfigureLocalization(app); // Enable static files so files in wwwroot can be found and served app.UseStaticFiles(); // Apply initial data in the database seeder.EnsureSeedInitialDataAsync().Wait();; // Enable Identity app.UseIdentity(); // Enable IdentityServer app.UseIdentityServer(); // Enable MVC with a default template app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}"); }); }
public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <ApiOptions> apiOptions, SeedDbData seeder) { // When in development if (env.IsDevelopment()) { // Log in Debug Window and in Console using the minimum log level from options loggerFactory.AddDebug(apiOptions.Value.LogLevel); loggerFactory.AddConsole(apiOptions.Value.LogLevel); } // When in staging/production else { // Log in files (using the Serilog library) using the minimum log level from options AwesomeMethods.CreateSerilogLogger(env, apiOptions.Value.LogLevel); loggerFactory.AddSerilog(); } // Custom Middleware for exception handling. This is added first in the pipeline to catch // unhandled exceptions from the whole request app.UseApiExceptionHandler(); // Uncomment the line below to raise exception for debugging purposes to test the above handler // app.UseExceptionRaiser(); // Configure the localization. en-US and el-GR cultures are supported with en-US being // the default one ConfigureLocalization(app); // Configure the field mapping between Models and ViewModels ConfigureMapping(); // Enable MVC. No routes specified here. We use attribute routing in controllers app.UseMvc(); // Apply initial data in the database seeder.EnsureSeedInitialDataAsync().Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAntiforgery antiforgery, SeedDbData seedData) { if (env.IsDevelopment()) { loggerFactory.AddSerilog(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, ConfigFile = "config/webpack.config.js" }); // NOTE: For SPA swagger needs adding before MVC // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) app.UseSwaggerUi(); } else { app.UseResponseCompression(); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859 try { using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { serviceScope.ServiceProvider.GetService <ApplicationDbContext>().Database.Migrate(); } } catch (Exception) { } } // Configure XSRF middleware, This pattern is for SPA style applications where XSRF token is added on Index page // load and passed back token on every subsequent async request app.Use(async(context, next) => { if (string.Equals(context.Request.Path.Value, "/", StringComparison.OrdinalIgnoreCase)) { var tokens = antiforgery.GetAndStoreTokens(context); context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, new CookieOptions() { HttpOnly = false }); } await next.Invoke(); }); app.UseStaticFiles(); app.UseIdentity(); // // Facebook Auth // app.UseFacebookAuthentication(new FacebookOptions() // { // AppId = Configuration["Authentication:Facebook:AppId"], // AppSecret = Configuration["Authentication:Facebook:AppSecret"] // }); // // Google Auth // app.UseGoogleAuthentication(new GoogleOptions() // { // ClientId = Configuration["Authentication:Google:ClientId"], // ClientSecret = Configuration["Authentication:Google:ClientSecret"] // }); // // Twitter Auth // // https://apps.twitter.com/ // app.UseTwitterAuthentication(new TwitterOptions() // { // ConsumerKey = Configuration["Authentication:Twitter:ConsumerKey"], // ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"] // }); // // Microsoft Auth // // https://apps.dev.microsoft.com/?mkt=en-us#/appList // app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions() // { // ClientId = Configuration["Authentication:Microsoft:ClientId"], // ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"] // }); // // Note: Below social providers are supported through this open source library: // // https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers // // Github Auth // // https://github.com/settings/developers // app.UseGitHubAuthentication(new GitHubAuthenticationOptions // { // ClientId = Configuration["Authentication:Github:ClientId"], // ClientSecret = Configuration["Authentication:Github:ClientSecret"] // }); // app.UseLinkedInAuthentication(new LinkedInAuthenticationOptions // { // ClientId = Configuration["Authentication:LinkedIn:ClientId"], // ClientSecret = Configuration["Authentication:LinkedIn:ClientSecret"] // }); app.UseMvc(routes => { routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); await seedData.EnsureSeedDataAsync(); }
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SeedDbData seedData) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); // Does not work with HTTPS //app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); // Ensure that we created the database try { using ( var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { serviceScope.ServiceProvider.GetService <ApplicationDbContext>().Database.Migrate(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } app.UseStaticFiles(); app.UseIdentity(); app.UseIdentityServer(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); await seedData.EnsureSeedDataAsync(); }
public static void Seed(this ApplicationDbContext context, IWebHost host, string hostname) { //// if (context.AllMigrationsApplied()) var seed = new SeedDbData(host, context, hostname); }