// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseCors("all"); app.UseAuthentication(); app.UseAuthorization(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); var context = _services.BuildServiceProvider().GetService <DataContext>(); DatabaseInitialiser.Initialise(context); }
public void Setup() { var options = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "Users") .Options; context = new DataContext(options); DatabaseInitialiser.Initialise(context); }
private static void CreateDbIfNotExists(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); DatabaseInitialiser.Initialise(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred creating the DB."); } } }