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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Deprecate IActionContextAccessor #62647

wants to merge 3 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 9, 2025

With the introduction of endpoint routing, IActionContextAccessor is no longer necessary as developers can access action descriptor and metadata information directly through HttpContext.GetEndpoint(). This change deprecates both the interface and its implementation to guide developers toward the modern approach.

Changes Made

Added Obsolete Attributes

  • Added [Obsolete] attribute to IActionContextAccessor interface with guidance message
  • Added [Obsolete] attribute to ActionContextAccessor class with same guidance message
  • Obsolete message: "IActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version."

Maintained Backward Compatibility

  • Added #pragma warning disable CS0618 around all internal framework usage to suppress warnings
  • Framework continues to use the deprecated APIs internally to maintain compatibility
  • All test code and test websites continue to function without build warnings

Migration Path

Developers should migrate from:

// Old approach
public class MyService
{
    private readonly IActionContextAccessor _accessor;
    
    public MyService(IActionContextAccessor accessor)
    {
        _accessor = accessor;
    }
    
    public void DoSomething()
    {
        var actionDescriptor = _accessor.ActionContext.ActionDescriptor;
        // ...
    }
}

To:

// New approach  
public class MyService
{
    private readonly IHttpContextAccessor _httpContextAccessor;
    
    public MyService(IHttpContextAccessor httpContextAccessor)
    {
        _httpContextAccessor = httpContextAccessor;
    }
    
    public void DoSomething()
    {
        var endpoint = _httpContextAccessor.HttpContext.GetEndpoint();
        var actionDescriptor = endpoint?.Metadata.GetMetadata<ActionDescriptor>();
        // ...
    }
}

Impact

  • External users: Will receive CS0618 deprecation warnings with clear migration guidance
  • Framework: Continues to function without changes, maintaining backward compatibility
  • Tests: All existing functionality validated and continues to work

This deprecation aligns with ASP.NET Core's architectural evolution toward endpoint routing and provides a cleaner, more direct way to access endpoint metadata.

Fixes #28162.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

Copilot AI and others added 2 commits July 9, 2025 23:54
@Copilot Copilot AI changed the title [WIP] Deprecate IActionContextAccessor Deprecate IActionContextAccessor Jul 10, 2025
@Copilot Copilot AI requested a review from captainsafia July 10, 2025 00:05
Copilot finished work on behalf of captainsafia July 10, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate IActionContextAccessor
2 participants