// 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,
                              FoodDbContext foodDbContext)
        {
            //  loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(errorApp =>
                {
                    errorApp.Run(async context =>
                    {
                        context.Response.StatusCode  = 500;
                        context.Response.ContentType = "text/plain";
                        var errorFeature             = context.Features.Get <IExceptionHandlerFeature>();
                        if (errorFeature != null)
                        {
                            var logger = loggerFactory.CreateLogger("Global exception logger");
                            logger.LogError(500, errorFeature.Error, errorFeature.Error.Message);
                        }

                        await context.Response.WriteAsync("There was an error");
                    });
                });
            }

            app.UseCors("AllowAllOrigins");
            AutoMapper.Mapper.Initialize(mapper =>
            {
                mapper.CreateMap <FoodItem, FoodItemDto>().ReverseMap();
                mapper.CreateMap <FoodItem, FoodItemUpdateDto>().ReverseMap();
                mapper.CreateMap <FoodItem, FoodItemCreateDto>().ReverseMap();
                mapper.CreateMap <Product, ProductDto>().ReverseMap();
                mapper.CreateMap <PeriodicElement, PeriodicElementDto>().ReverseMap();
                //    mapper.CreateMap<Product, ProductUpdateDto>().ReverseMap();
                mapper.CreateMap <Entities.Author, Models.AuthorDto>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src =>
                                                                 $"{src.FirstName} {src.LastName}"))
                .ForMember(dest => dest.Age, opt => opt.MapFrom(src =>
                                                                src.DateOfBirth.GetCurrentAge()));

                mapper.CreateMap <Entities.Book, Models.BookDto>();

                mapper.CreateMap <Models.AuthorForCreationDto, Entities.Author>();

                mapper.CreateMap <Models.BookForCreationDto, Entities.Book>();

                mapper.CreateMap <Models.BookForUpdateDto, Entities.Book>();

                mapper.CreateMap <Entities.Book, Models.BookForUpdateDto>();
            });
            foodDbContext.EnsureSeedDataForContext();

            // IdentityServer4.AccessTokenValidation: authentication middleware for the API.
            app.UseIdentityServer();

            app.UseAuthentication();

            app.UseStaticFiles();
            app.UseDefaultFiles();

            app.UseSignalR(routes =>
            {
                routes.MapHub <FoodHub>("/foodhub");
            });
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "FoodAPICore V1");
            });

            app.UseMvcWithDefaultRoute();
        }