A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/aspnet/AspNetCore/issues/5144 below:

HttpContext property of HttpContextAccessor is null · Issue #5144 · dotnet/aspnetcore · GitHub


I have a REST API web application which worked perfectly with ASP.Net Core 2.1. Now the constructor injected IHttpContextAccessor returns a null value for HttpContext property.

In Startup.cs class, in ConfigureServices method I have:

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();          
services.AddScoped<WorklistPagedTasksHalRepresentationConverter>();

This is the WorklistPagedTasksHalRepresentationConverter class

public class WorklistPagedTasksHalRepresentationConverter : TypeConverter<WorklistWithPagedTasks, WorklistPagedTasksHalRepresentation>
    {
        private readonly IHttpContextAccessor httpContextAccessor;

        private readonly IMapper mapper;

        public WorklistPagedTasksHalRepresentationConverter(IHttpContextAccessor httpContextAccessor, IMapper mapper)
        {
            this.httpContextAccessor = httpContextAccessor;
            this.mapper = mapper;
        }

        public WorklistPagedTasksHalRepresentation Convert(WorklistWithPagedTasks source, WorklistPagedTasksHalRepresentation destination, ResolutionContext context)
        {
            var tasks = mapper.Map<IList<TaskSummaryHalRepresentation>>(source.Tasks.ResultPage.ToList());
            var worklistPagedTasksHalRepresentation = new WorklistPagedTasksHalRepresentation(
                new PaginatedResult<TaskSummaryHalRepresentation>
                {
                    ResultPage = tasks.AsQueryable(),
                    TotalCount = source.Tasks.TotalCount,
                    PageNumber = source.Tasks.PageNumber
                },
                httpContextAccessor.HttpContext.Request)
            {
                Id = source.Id,
                OwnerId = source.OwnerId,
                OwnerName = source.OwnerName
            };
            return worklistPagedTasksHalRepresentation;
        }
    }

The Convert method is called by a controller method.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4