Cannot resolve scoped service 'Microsoft.AspNetCore.Http.IHttpContextAccessor' from root provider.
services.AddScoped<IHttpContextAccessor, HttpContextAccessor>();
.net core3.1 注册IHttpContextAccessor 报错,有知道什么原因的吗?
人家要是Singleton的... 有一个系统自己的注册扩展方法. 在HttpServiceCollectionExtensions.AddHttpContextAccessor.
不能AddScoped吗
@hslgmq: 你可以测试一下下面的伪代码. 应该就是抛出这个异常了. 可以体会体会.
ServiceCollection sc=new();
sc.AddScope<myObject>();
sc.BuildServiceProvider(new (){ValidScopes=true}).GetService<MyOjbect>() // Throw Cannot resolve scoped service ... from root provider.