Skip to content

Deprecate IActionContextAccessor #62647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace IActionContextAccessor with IHttpContextAccessor throughout t…
…he codebase

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
  • Loading branch information
Copilot and captainsafia committed Jul 15, 2025
commit 843dfd33f9fd01e727ce44affc2efd10668e2927
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure;
/// <summary>
/// Type that provides access to an <see cref="ActionContext"/>.
/// </summary>
[Obsolete("ActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version.")]
public class ActionContextAccessor : IActionContextAccessor
{
internal static readonly IActionContextAccessor Null = new NullActionContextAccessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ internal partial class ControllerActionInvoker : ResourceInvoker, IActionInvoker
internal ControllerActionInvoker(
ILogger logger,
DiagnosticListener diagnosticListener,
#pragma warning disable CS0618 // Type or member is obsolete
IActionContextAccessor actionContextAccessor,
#pragma warning restore CS0618 // Type or member is obsolete
IActionResultTypeMapper mapper,
ControllerContext controllerContext,
ControllerActionInvokerCacheEntry cacheEntry,
IFilterMetadata[] filters)
: base(diagnosticListener, logger, actionContextAccessor, mapper, controllerContext, filters, controllerContext.ValueProviderFactories)
: base(diagnosticListener, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories)
{
ArgumentNullException.ThrowIfNull(cacheEntry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,13 @@ internal sealed class ControllerActionInvokerProvider : IActionInvokerProvider
private readonly ILogger _logger;
private readonly DiagnosticListener _diagnosticListener;
private readonly IActionResultTypeMapper _mapper;
#pragma warning disable CS0618 // Type or member is obsolete
private readonly IActionContextAccessor _actionContextAccessor;
#pragma warning restore CS0618 // Type or member is obsolete

public ControllerActionInvokerProvider(
ControllerActionInvokerCache controllerActionInvokerCache,
IOptions<MvcOptions> optionsAccessor,
ILoggerFactory loggerFactory,
DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper)
: this(controllerActionInvokerCache, optionsAccessor, loggerFactory, diagnosticListener, mapper, null)
{
}

public ControllerActionInvokerProvider(
ControllerActionInvokerCache controllerActionInvokerCache,
IOptions<MvcOptions> optionsAccessor,
ILoggerFactory loggerFactory,
DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper,
#pragma warning disable CS0618 // Type or member is obsolete
IActionContextAccessor? actionContextAccessor)
#pragma warning restore CS0618 // Type or member is obsolete
{
_controllerActionInvokerCache = controllerActionInvokerCache;
_valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
Expand All @@ -55,9 +39,6 @@ public ControllerActionInvokerProvider(
_logger = loggerFactory.CreateLogger(typeof(ControllerActionInvoker));
_diagnosticListener = diagnosticListener;
_mapper = mapper;
#pragma warning disable CS0618 // Type or member is obsolete
_actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
#pragma warning restore CS0618 // Type or member is obsolete
}

public int Order => -1000;
Expand All @@ -83,7 +64,6 @@ public void OnProvidersExecuting(ActionInvokerProviderContext context)
var invoker = new ControllerActionInvoker(
_logger,
_diagnosticListener,
_actionContextAccessor,
_mapper,
controllerContext,
cacheEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure;
/// <summary>
/// Defines an interface for exposing an <see cref="ActionContext"/>.
/// </summary>
[Obsolete("IActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version.")]
public interface IActionContextAccessor
{
/// <summary>
Expand Down
9 changes: 0 additions & 9 deletions src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ internal abstract partial class ResourceInvoker
{
protected readonly DiagnosticListener _diagnosticListener;
protected readonly ILogger _logger;
#pragma warning disable CS0618 // Type or member is obsolete
protected readonly IActionContextAccessor _actionContextAccessor;
#pragma warning restore CS0618 // Type or member is obsolete
protected readonly IActionResultTypeMapper _mapper;
protected readonly ActionContext _actionContext;
protected readonly IFilterMetadata[] _filters;
Expand All @@ -39,17 +36,13 @@ internal abstract partial class ResourceInvoker
public ResourceInvoker(
DiagnosticListener diagnosticListener,
ILogger logger,
#pragma warning disable CS0618 // Type or member is obsolete
IActionContextAccessor actionContextAccessor,
#pragma warning restore CS0618 // Type or member is obsolete
IActionResultTypeMapper mapper,
ActionContext actionContext,
IFilterMetadata[] filters,
IList<IValueProviderFactory> valueProviderFactories)
{
_diagnosticListener = diagnosticListener ?? throw new ArgumentNullException(nameof(diagnosticListener));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_actionContextAccessor = actionContextAccessor ?? throw new ArgumentNullException(nameof(actionContextAccessor));
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_actionContext = actionContext ?? throw new ArgumentNullException(nameof(actionContext));

Expand All @@ -65,7 +58,6 @@ public virtual Task InvokeAsync()
return Logged(this);
}

_actionContextAccessor.ActionContext = _actionContext;
var scope = _logger.ActionScope(_actionContext.ActionDescriptor);

Task task;
Expand Down Expand Up @@ -100,7 +92,6 @@ static async Task Awaited(ResourceInvoker invoker, Task task, IDisposable? scope
static async Task Logged(ResourceInvoker invoker)
{
var actionContext = invoker._actionContext;
invoker._actionContextAccessor.ActionContext = actionContext;
try
{
var logger = invoker._logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ internal sealed class ControllerRequestDelegateFactory : IRequestDelegateFactory
private readonly ILogger _logger;
private readonly DiagnosticListener _diagnosticListener;
private readonly IActionResultTypeMapper _mapper;
#pragma warning disable CS0618 // Type or member is obsolete
private readonly IActionContextAccessor _actionContextAccessor;
#pragma warning restore CS0618 // Type or member is obsolete
private readonly bool _enableActionInvokers;

public ControllerRequestDelegateFactory(
Expand All @@ -35,19 +32,6 @@ public ControllerRequestDelegateFactory(
ILoggerFactory loggerFactory,
DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper)
: this(controllerActionInvokerCache, optionsAccessor, loggerFactory, diagnosticListener, mapper, null)
{
}

public ControllerRequestDelegateFactory(
ControllerActionInvokerCache controllerActionInvokerCache,
IOptions<MvcOptions> optionsAccessor,
ILoggerFactory loggerFactory,
DiagnosticListener diagnosticListener,
IActionResultTypeMapper mapper,
#pragma warning disable CS0618 // Type or member is obsolete
IActionContextAccessor? actionContextAccessor)
#pragma warning restore CS0618 // Type or member is obsolete
{
_controllerActionInvokerCache = controllerActionInvokerCache;
_valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
Expand All @@ -58,9 +42,6 @@ public ControllerRequestDelegateFactory(
_logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
_diagnosticListener = diagnosticListener;
_mapper = mapper;
#pragma warning disable CS0618 // Type or member is obsolete
_actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
#pragma warning restore CS0618 // Type or member is obsolete
}

public RequestDelegate? CreateRequestDelegate(ActionDescriptor actionDescriptor, RouteValueDictionary? dataTokens)
Expand Down Expand Up @@ -100,7 +81,6 @@ public ControllerRequestDelegateFactory(
var invoker = new ControllerActionInvoker(
_logger,
_diagnosticListener,
_actionContextAccessor,
_mapper,
controllerContext,
cacheEntry,
Expand Down
3 changes: 0 additions & 3 deletions src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@ public TestControllerActionInvoker(
: base(
logger,
diagnosticListener,
#pragma warning disable CS0618 // Type or member is obsolete
ActionContextAccessor.Null,
#pragma warning restore CS0618 // Type or member is obsolete
mapper,
CreateControllerContext(actionContext, valueProviderFactories, maxAllowedErrorsInModelState),
CreateCacheEntry((ControllerActionDescriptor)actionContext.ActionDescriptor, controllerFactory),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1432,9 +1432,6 @@ public async Task Invoke_UsesDefaultValuesIfNotBound()
var invoker = new ControllerActionInvoker(
new NullLoggerFactory().CreateLogger<ControllerActionInvoker>(),
new DiagnosticListener("Microsoft.AspNetCore"),
#pragma warning disable CS0618 // Type or member is obsolete
ActionContextAccessor.Null,
#pragma warning restore CS0618 // Type or member is obsolete
new ActionResultTypeMapper(),
controllerContext,
cacheEntry,
Expand Down Expand Up @@ -1771,9 +1768,6 @@ private ControllerActionInvoker CreateInvoker(
var invoker = new ControllerActionInvoker(
logger,
diagnosticSource,
#pragma warning disable CS0618 // Type or member is obsolete
ActionContextAccessor.Null,
#pragma warning restore CS0618 // Type or member is obsolete
new ActionResultTypeMapper(),
controllerContext,
cacheEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public PageActionInvoker(
IPageHandlerMethodSelector handlerMethodSelector,
DiagnosticListener diagnosticListener,
ILogger logger,
#pragma warning disable CS0618 // Type or member is obsolete
IActionContextAccessor actionContextAccessor,
#pragma warning restore CS0618 // Type or member is obsolete
IActionResultTypeMapper mapper,
PageContext pageContext,
IFilterMetadata[] filterMetadata,
Expand All @@ -47,7 +44,6 @@ public PageActionInvoker(
: base(
diagnosticListener,
logger,
actionContextAccessor,
mapper,
pageContext,
filterMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ internal sealed class PageActionInvokerProvider : IActionInvokerProvider
private readonly DiagnosticListener _diagnosticListener;
private readonly ILogger<PageActionInvoker> _logger;
private readonly IActionResultTypeMapper _mapper;
#pragma warning disable CS0618 // Type or member is obsolete
private readonly IActionContextAccessor _actionContextAccessor;
#pragma warning restore CS0618 // Type or member is obsolete

public PageActionInvokerProvider(
PageLoader pageLoader,
Expand All @@ -39,10 +36,7 @@ public PageActionInvokerProvider(
IPageHandlerMethodSelector selector,
DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory,
IActionResultTypeMapper mapper,
#pragma warning disable CS0618 // Type or member is obsolete
IActionContextAccessor? actionContextAccessor = null)
#pragma warning restore CS0618 // Type or member is obsolete
IActionResultTypeMapper mapper)
{
_pageLoader = pageLoader;
_pageActionInvokerCache = pageActionInvokerCache;
Expand All @@ -54,9 +48,6 @@ public PageActionInvokerProvider(
_diagnosticListener = diagnosticListener;
_logger = loggerFactory.CreateLogger<PageActionInvoker>();
_mapper = mapper;
#pragma warning disable CS0618 // Type or member is obsolete
_actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
#pragma warning restore CS0618 // Type or member is obsolete
}

// For testing
Expand Down Expand Up @@ -96,7 +87,6 @@ public void OnProvidersExecuting(ActionInvokerProviderContext context)
_selector,
_diagnosticListener,
_logger,
_actionContextAccessor,
_mapper,
pageContext,
filters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ internal sealed class PageRequestDelegateFactory : IRequestDelegateFactory
private readonly DiagnosticListener _diagnosticListener;
private readonly ILogger<PageActionInvoker> _logger;
private readonly IActionResultTypeMapper _mapper;
#pragma warning disable CS0618 // Type or member is obsolete
private readonly IActionContextAccessor _actionContextAccessor;
#pragma warning restore CS0618 // Type or member is obsolete
private readonly bool _enableActionInvokers;

public PageRequestDelegateFactory(
Expand All @@ -41,23 +38,6 @@ public PageRequestDelegateFactory(
DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory,
IActionResultTypeMapper mapper)
: this(cache, modelMetadataProvider, tempDataFactory, mvcOptions, mvcViewOptions, selector, diagnosticListener, loggerFactory, mapper, null)
{
}

public PageRequestDelegateFactory(
PageActionInvokerCache cache,
IModelMetadataProvider modelMetadataProvider,
ITempDataDictionaryFactory tempDataFactory,
IOptions<MvcOptions> mvcOptions,
IOptions<MvcViewOptions> mvcViewOptions,
IPageHandlerMethodSelector selector,
DiagnosticListener diagnosticListener,
ILoggerFactory loggerFactory,
IActionResultTypeMapper mapper,
#pragma warning disable CS0618 // Type or member is obsolete
IActionContextAccessor? actionContextAccessor)
#pragma warning restore CS0618 // Type or member is obsolete
{
_cache = cache;
_valueProviderFactories = mvcOptions.Value.ValueProviderFactories.ToArray();
Expand All @@ -69,9 +49,6 @@ public PageRequestDelegateFactory(
_diagnosticListener = diagnosticListener;
_logger = loggerFactory.CreateLogger<PageActionInvoker>();
_mapper = mapper;
#pragma warning disable CS0618 // Type or member is obsolete
_actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
#pragma warning restore CS0618 // Type or member is obsolete
}

public RequestDelegate? CreateRequestDelegate(ActionDescriptor actionDescriptor, RouteValueDictionary? dataTokens)
Expand Down Expand Up @@ -109,7 +86,6 @@ public PageRequestDelegateFactory(
_selector,
_diagnosticListener,
_logger,
_actionContextAccessor,
_mapper,
pageContext,
filters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1565,9 +1565,6 @@ object pageFactory(PageContext context, ViewContext viewContext)
selector.Object,
diagnosticListener ?? new DiagnosticListener("Microsoft.AspNetCore"),
logger ?? NullLogger.Instance,
#pragma warning disable CS0618 // Type or member is obsolete
ActionContextAccessor.Null,
#pragma warning restore CS0618 // Type or member is obsolete
new ActionResultTypeMapper(),
pageContext,
filters ?? Array.Empty<IFilterMetadata>(),
Expand Down
3 changes: 0 additions & 3 deletions src/Mvc/test/WebSites/BasicWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddHttpContextAccessor();
services.AddScoped<RequestIdService>();
services.AddScoped<TestResponseGenerator>();
#pragma warning disable CS0618 // Type or member is obsolete
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
#pragma warning restore CS0618 // Type or member is obsolete
}

public void Configure(IApplicationBuilder app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<RequestIdService>();
services.AddTransient<ServiceActionFilter>();
services.AddScoped<TestResponseGenerator>();
#pragma warning disable CS0618 // Type or member is obsolete
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
#pragma warning restore CS0618 // Type or member is obsolete
services.TryAddSingleton(CreateWeatherForecastService);
}

Expand Down
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy