HttpContextInstance
Description
Global thread-safe access to the current HttpContext — the .NET Framework HttpContext.Current pattern brought back for ASP.NET Core.
Features
HttpContextInstance.Current: returns the currentHttpContextfrom anywhere without injection
Behavior
var context = HttpContextInstance.Current;
var path = context.Request?.Path;
Caveats
- If no active HTTP context exists, returns a default
HttpContextwith an emptyClaimsPrincipaland the framework service provider — never returnsnull. - Returns a default empty context (not null) outside of HTTP requests — console apps, background jobs, unit tests
- Requires
AddFrameworkServices()to be called at startup — registered automatically by the framework
Tip
Use HttpContextInstance.Current in static helpers and extension methods where injection is not available.