// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MMTContext mmtContext) { mmtContext.Database.Migrate(); var seeder = new MMTContextSeed(); seeder.Seed(mmtContext); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API"); }); app.UseMiddleware <CustomExceptionMiddleware>(); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public void Setup() { var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .BuildServiceProvider(); var builder = new DbContextOptionsBuilder <MMTContext>(); builder.UseSqlServer($"Server=(localdb)\\mssqllocaldb;Database=MMTShop_db_{Guid.NewGuid()};Trusted_Connection=True;MultipleActiveResultSets=true") .UseInternalServiceProvider(serviceProvider); _context = new MMTContext(builder.Options); _context.Database.Migrate(); var seeder = new MMTContextSeed(); seeder.Seed(_context); }