Table of Contents

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 current HttpContext from anywhere without injection

Behavior

var context = HttpContextInstance.Current;
var path = context.Request?.Path;

Caveats

  • If no active HTTP context exists, returns a default HttpContext with an empty ClaimsPrincipal and the framework service provider — never returns null.
  • 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.