Trying to inject a service,
1 2 3 4 5 |
var builder = WebApplication.CreateBuilder(args); builder.Services.AddGrpc(); builder.Services.AddSingleton<GrpcHeaderManager>(); var app = builder.Build(); app.Run(); |
Then got the above error. The reason is HttpContextAccessor is no longer wired up by default, you have to register it manually.
Just add one line of code
1 |
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
or this line
1 |
builder.Services.AddHttpContextAccessor(); |
solved the error.