// 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, TrailerCheckContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitialiser.Initialise(context); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, DatabaseContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitialiser.Initialise(context); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var env = services.GetRequiredService <IWebHostEnvironment>(); var context = services.GetRequiredService <LrpDbContext>(); if (env.IsDevelopment()) { context.Database.EnsureDeleted(); } context.Database.EnsureCreated(); DbInitialiser.Initialise(context); var authContext = services.GetRequiredService <AccountsContext>(); authContext.Database.EnsureCreated(); authContext.Database.Migrate(); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "A Seeding Error Occured"); } } host.Run(); }
private static void CreateDbIfNotExists(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <UserContext>(); //context.Database.EnsureCreated(); DbInitialiser.Initialise(context); } }
// 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, ApplicationDbContext context, UserManager <ApplicationUser> userManager, IServiceProvider serviceProvider) { app.UseSession(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitialiser.Initialise(context); await CreateRoles(serviceProvider); /*Assign other users to 'Customer' category*/ ICollection <ApplicationUser> appUsers = context.ApplicationUsers.ToList(); if (appUsers.Count > 0) { foreach (var user in appUsers) { var roleCount = userManager.GetRolesAsync(user).Result.Count(); if (roleCount < 1)//If user doesn't have a role { await userManager.AddToRoleAsync(user, "Customer"); } } } }
private async Task RunAsync() { var services = ConfigureServices(); var provider = services.BuildServiceProvider(); var dbContext = provider.GetRequiredService <CraigBotDbContext>(); await DbInitialiser.Initialise(dbContext); provider.GetRequiredService <ILoggingService>(); provider.GetRequiredService <ICommandHandler>(); await provider.GetRequiredService <IStartupService>().StartClient(); await Task.Delay(-1); }
private static void CreateDbIfNotExists(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); DbInitialiser.Initialise(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred creating the DB."); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ZipCoContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/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(); } RewriteOptions option = new RewriteOptions(); option.AddRedirect("^$", "swagger"); app.UseRewriter(option); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapRazorPages(); }); // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint. app.UseSwaggerUI(q => { q.SwaggerEndpoint("/swagger/v1/swagger.json", "ZipCo API v1"); }); DbInitialiser.Initialise(context); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <PaymentContext>(); DbInitialiser.Initialise(context); } catch (Exception e) { } } host.Run(); }
private static void MigrateAndSeedDatabase(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <BlimpBotContext>(); DbInitialiser.Initialise(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred creating the DB."); } } }
public void Initialise_When_Users_Is_Not_Empty_Does_Not_Populate_Users() { // Arrange _quizManagerContext.Users.Add(new User() { Username = "******", Password = "******", Role = "TestRole" }); _quizManagerContext.SaveChanges(); _quizManagerContext.Quizzes.Add(new Quiz() { Title = "The Software Development Lifecycle" }); _quizManagerContext.SaveChanges(); _quizManagerContext.Questions.Add(new Question() { QuizId = _quizManagerContext.Quizzes.Single(x => x.Title == "The Software Development Lifecycle").Id, Text = "At which point in the software development lifecycle is a system design document produced?" }); _quizManagerContext.SaveChanges(); _quizManagerContext.Answers.Add(new Answer() { QuestionId = _quizManagerContext.Questions.Single(x => x.Text == "At which point in the software development lifecycle is a system design document produced?").Id, Text = "Deployment/implementation." }); _quizManagerContext.SaveChanges(); var expectedNumberOfUsers = 1; var expectedNumberOfQuizzes = 1; var expectedNumberOfQuestions = 1; var expectedNumberOfAnswers = 1; // Act DbInitialiser.Initialise(_quizManagerContext); var actualNumberOfUsers = _quizManagerContext.Users.Count(); var actualNumberOfQuizzes = _quizManagerContext.Quizzes.Count(); var actualNumberOfQuestions = _quizManagerContext.Questions.Count(); var actualNumberOfAnswers = _quizManagerContext.Answers.Count(); // Assert Assert.AreEqual(expectedNumberOfUsers, actualNumberOfUsers); Assert.AreEqual(expectedNumberOfQuizzes, actualNumberOfQuizzes); Assert.AreEqual(expectedNumberOfQuestions, actualNumberOfQuestions); Assert.AreEqual(expectedNumberOfAnswers, actualNumberOfAnswers); }
public static void Main(string[] args) { var webHost = BuildWebHost(args); using (var scope = webHost.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <QuestionGeneratorContext>(); DbInitialiser.Initialise(context); } catch (Exception exception) { throw exception; } } webHost.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); DbInitialiser.Initialise(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope())//依赖注入 { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <SchoolDbContext>(); DbInitialiser.Initialise(context); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e.Message, "初始化系统测试数据时出错,请联系管理员!"); } } host.Run(); }
public void Initialise_When_Database_Is_Empty_Populates_Database() { // Arrange var expectedNumberOfUsers = 3; var expectedNumberOfQuizzes = 3; var expectedNumberOfQuestions = 12; var expectedNumberOfAnswers = 48; // Act DbInitialiser.Initialise(_quizManagerContext); var actualNumberOfUsers = _quizManagerContext.Users.Count(); var actualNumberOfQuizzes = _quizManagerContext.Quizzes.Count(); var actualNumberOfQuestions = _quizManagerContext.Questions.Count(); var actualNumberOfAnswers = _quizManagerContext.Answers.Count(); // Assert Assert.AreEqual(expectedNumberOfUsers, actualNumberOfUsers); Assert.AreEqual(expectedNumberOfQuizzes, actualNumberOfQuizzes); Assert.AreEqual(expectedNumberOfQuestions, actualNumberOfQuestions); Assert.AreEqual(expectedNumberOfAnswers, actualNumberOfAnswers); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { DbInitialiser.Initialise(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred 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, WebshopDbContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, AddressService addressService, ILoggerFactory loggerFactory) { loggerFactory.AddAzureWebAppDiagnostics(); loggerFactory.AddConsole(); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseSession(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); if (_hostingEnvironment.IsProduction() || _hostingEnvironment.IsStaging() || _hostingEnvironment.EnvironmentName == "IntegratedDb" || _hostingEnvironment.EnvironmentName == "LocalSql") { context.Database.Migrate(); } DbInitialiser.Initialise(context, userManager, roleManager, addressService); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; Logger = services.GetRequiredService <ILogger <Program> >(); try { var context = services.GetRequiredService <NbaDbContext>(); context.Database.Migrate(); var initialiser = new DbInitialiser(context); initialiser.Initialise(); } catch (Exception ex) { Logger.LogError(ex, "An error occured creating the database."); } } host.Run(); }