📅  最后修改于: 2022-03-11 14:48:58.049000             🧑  作者: Mango
It is no longer a default service. You have to configure it in Startup.cs
services.TryAddSingleton();
services.TryAddSingleton();
UPDATE: In ASP.NET Core 2.1, the AddHttpContextAccessor helper extension method was added to correctly register the IHttpContextAccessor with the correct lifetime (singleton). So, in ASP.NET Core 2.1 and above, the code should be
services.AddHttpContextAccessor();
services.TryAddSingleton();