Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor'

An unhandled exception occurred while processing the request.

InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' while attempting to activate 'DInjectionProvider.WholeInjection'.

Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, bool throwIfCallSiteNotFound)

As of .NET Core 2.1 there is an extension method that has been added to correctly register an IHttpContextAccessor as a singleton. See Add helper to register IHttpContextAccessor #947. Simply add as follows in your ConfigureServices() method:

services.AddHttpContextAccessor();

转载于:https://www.cnblogs.com/asd14828/p/11136814.html

你可能感兴趣的:(Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor')