// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, LibraryDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(appBuilder => { appBuilder.Run(async con => { con.Response.StatusCode = 500; await con.Response.WriteAsync("Unexpexcted fault heppend, please try again later."); }); }); } context.EnsureSeedDataForContext(); AutoMapper.Mapper.Initialize(config => { config.CreateMap <Entity.Author, Models.AuthorVM>() .ForMember(dest => dest.Name, opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}")) .ForMember(dest => dest.Age, opt => opt.MapFrom(src => src.DateOfBirth.GetCurrentAge(src.DateOfDeath))); config.CreateMap <Entity.Book, Models.BookVM>(); config.CreateMap <Models.AuthorCreateVM, Entity.Author>(); config.CreateMap <Models.BookCreateVM, Entity.Book>(); config.CreateMap <Models.AuthorCreateDateOfDeathVM, Entity.Author>(); config.CreateMap <Models.BookUpdateVM, Entity.Book>(); config.CreateMap <Entity.Book, Models.BookUpdateVM>(); config.CreateMap <Models.AuthorUpdateVM, Entity.Author>(); config.CreateMap <Entity.Author, Models.AuthorUpdateVM>(); }); app.UseIpRateLimiting(); app.UseResponseCaching(); app.UseHttpCacheHeaders(); app.UseMvc(); //app.Run(async (context) => //{ // await context.Response.WriteAsync("Hello World!"); //}); }