public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetRequiredService <BloggingDbContext>(); // context.Database.Migrate(); var dbCreatedCurrently = context.Database.EnsureCreated(); if (env.IsDevelopment() && dbCreatedCurrently) { var seed = new TestDataSeeder(Configuration); seed.SeedData(); } } app.UseRouting(); app.UseCors("default"); app.UseMultiTenant(); app.UseAuthentication(); app.UseAuthorization(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "The API V1"); c.OAuthClientId("the_api_swagger"); c.OAuthAppName("The API - Swagger"); // c.OAuthUsePkce(); }); app.UseEndpoints(endpoints => { // endpoints.MapControllers().RequireAuthorization("ApiScope"); endpoints.MapControllers(); }); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetRequiredService <BloggingDbContext>(); // context.Database.Migrate(); var dbCreatedCurrently = context.Database.EnsureCreated(); if (env.IsDevelopment() && dbCreatedCurrently) { var seed = new TestDataSeeder(Configuration); seed.SeedData(); } } app.UseRouting(); app.UseCors("default"); app.UseMultiTenant(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers() .RequireAuthorization("ApiScope"); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); string dbName = "TestDb"; services.AddDbContext <AppDbContext>(options => options.UseInMemoryDatabase(databaseName: dbName)); //var context = services.GetRequiredService<AppDbContext>(); var builder = new DbContextOptionsBuilder <AppDbContext>(); builder.UseInMemoryDatabase <AppDbContext>(dbName); var context = new AppDbContext(builder.Options); if (!context.Movies.Any()) { var tds = new TestDataSeeder(context); tds.SeedData(); } var config = new AutoMapper.MapperConfiguration(cfg => cfg.AddProfile(new AutoMapperProfileConfiguration())); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddTransient <IMovieService, MovieService>(); services.AddTransient <IMovieRepository, MovieRepository>(); services.AddTransient <IUnitOfWork, UnitOfWork>(); services.AddTransient <IMemoryCache, MemoryCache>(); }