// 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, OnlineGameContext onlineGameContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(appBuilder => { appBuilder.Run(async context => { var exceptionHandlerFeature = context.Features.Get <IExceptionHandlerFeature>(); if (exceptionHandlerFeature != null) { var logger = loggerFactory.CreateLogger("Global exception logger"); logger.LogError(500, exceptionHandlerFeature.Error, exceptionHandlerFeature.Error.Message); } context.Response.StatusCode = 500; await context.Response.WriteAsync("An unexpected fault happened. Try again later."); }); }); } app.UseCors(c => c.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); MapperHelper.InitMapperConf(); app.UseResponseCaching(); app.UseHttpsRedirection(); app.UseAuthentication(); app.UseMvc(); }
private void SeedInMemoryStore() { MapperHelper.InitMapperConf(); using (var context = new OnlineGameContext(_options)) { context.Database.EnsureCreated(); context.Games.AddRange(GamesTestData.FirstGame, GamesTestData.ThirdGame, GamesTestData.FourthGame); context.SaveChanges(); } }
public void Database() { _options = new DbContextOptionsBuilder <OnlineGameContext>() .UseInMemoryDatabase().Options; SeedInMemoryStore(); var context = new OnlineGameContext(_options); var gameRepository = new GameRepository(context); var commentRepository = new CommentRepository(context); PublisherRepository = new PublisherRepository(context); GameService = new GameService(gameRepository, new DefaultValidatorStrategy <GameModel>()); CommentService = new CommentService(commentRepository, new DefaultValidatorStrategy <CommentModel>()); }