How to Inject Custom Http Response Header Click to Watch Video

Asp.Net Core 3.1 Dependency Injection Error Unable to resolve service for type 'Microsoft.AspNetCore.Http.HttpContext

Error: Unable to resolve service for type 'Microsoft.AspNetCore.Http.HttpContext

Solution: There is a chance that you are trying to inject none Interface into a Class's Constructor. Remember, Dependency Injection works with Interfaces that have been registered with the Service Container in the Startup.cs Class file. When you try to inject HttpContext in the Constructor, the Error happens. For a solution to solve this problem see below:

  • Change HttpContext httpContext to IHttpContextAccessor contextAccessor in the Constructor of your Class, the error should be resolved.
  • Please leave a message below if this solution helped you, other users might want to see how you resolved the issue. Thank you. 

md said:

Thank you bro.. it helped me..

Posted On: January 27, 2022 7:46:08 AM

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy