IHttpContextAccessor is no longer wired up by default, you have to register it yourself
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
As of .NET Core 2.1 there is an extension method that has been added to correctly register an IHttpContextAccessor
as a singleton. See Add helper to register IHttpContextAccessor #947. Simply add as follows in your ConfigureServices()
method:
services.AddHttpContextAccessor();
This is equivalent to:
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With