I have builder.Services.AddHttpContextAccessor(); in my program.cs
but keep getting the following error when I try to run the app
Unable to resolve service for type 'Microsoft.AspNetCore.Http.HttpContextAccessor' while attempting to activate
I have builder.Services.AddHttpContextAccessor(); in my program.cs
but keep getting the following error when I try to run the app
Unable to resolve service for type 'Microsoft.AspNetCore.Http.HttpContextAccessor' while attempting to activate
https://stackoverflow.com/a/75520898/5290908
For .NET Core 7.0, add the following code in the Program.cs class:
builder.Services.AddHttpContextAccessor();
This is equivalent to:
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
Thanks for your help. I've figured it out. The consturctor was using HttpContextAccessor instead of IHttpContextAccessor.