I am getting an error like this:
Cannot consume scoped service 'Microsoft.AspNetCore.Http.IHttpContextAccessor' from singleton 'MyNamespace.IMyCustomThing'
I am confused, because I register IHttpContextAccessor
by calling services.AddHttpContextAccessor()
. The code for AddHttpContextAccessor is here. The relevant part is this:
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
IHttpContextAccessor is registered as a singleton. Why does ASP.Net Core think it is a scoped service?
NOTE: Incase it is relevant, IMyCustomThing
uses the IHttpContextAccessor
to see if there is a current HttpContext
, if there is not then it takes other actions.