Skip to content

Commit 69b5f41

Browse files
authored
Document IActionContextAccessor deprecation breaking change for .NET 10 (#47891)
1 parent e0f747b commit 69b5f41

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

docs/core/compatibility/10.0.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
1717
1818
## ASP.NET Core
1919

20-
| Title | Type of change | Introduced version |
21-
|-------|----------------|--------------------|
20+
| Title | Type of change | Introduced version |
21+
|-------|-------------------|--------------------|
22+
| [IActionContextAccessor and ActionContextAccessor are obsolete](aspnet-core/10/iactioncontextaccessor-obsolete.md) | Source incompatible/behavioral change | Preview 7 |
2223
| [IncludeOpenAPIAnalyzers property and MVC API analyzers are deprecated](aspnet-core/10/openapi-analyzers-deprecated.md) | Source incompatible | Preview 7 |
2324
| [Microsoft.Extensions.ApiDescription.Client package deprecated](aspnet-core/10/apidescription-client-deprecated.md) | Source incompatible | Preview 7 |
2425

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: "IActionContextAccessor and ActionContextAccessor are obsolete"
3+
description: "Learn about the breaking change in ASP.NET Core 10 where IActionContextAccessor and ActionContextAccessor are marked as obsolete."
4+
ms.date: 08/07/2025
5+
ai-usage: ai-assisted
6+
ms.custom: https://github.com/aspnet/Announcements/issues/520
7+
---
8+
9+
# IActionContextAccessor and ActionContextAccessor are obsolete
10+
11+
<xref:Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor> and <xref:Microsoft.AspNetCore.Mvc.Infrastructure.ActionContextAccessor> have been marked as obsolete with diagnostic ID `ASPDEPR006`. With the introduction of endpoint routing, `IActionContextAccessor` is no longer necessary as developers can access action descriptor and metadata information directly through `HttpContext.GetEndpoint()`.
12+
13+
## Version introduced
14+
15+
.NET 10 Preview 7
16+
17+
## Previous behavior
18+
19+
Previously, you could use `IActionContextAccessor` to access the current <xref:Microsoft.AspNetCore.Mvc.ActionContext>:
20+
21+
```csharp
22+
public class MyService
23+
{
24+
private readonly IActionContextAccessor _actionContextAccessor;
25+
26+
public MyService(IActionContextAccessor actionContextAccessor)
27+
{
28+
_actionContextAccessor = actionContextAccessor;
29+
}
30+
31+
public void DoSomething()
32+
{
33+
var actionContext = _actionContextAccessor.ActionContext;
34+
var actionDescriptor = actionContext?.ActionDescriptor;
35+
// Use action descriptor metadata.
36+
}
37+
}
38+
```
39+
40+
## New behavior
41+
42+
Starting in .NET 10, using `IActionContextAccessor` and `ActionContextAccessor` produces a compiler warning with diagnostic ID `ASPDEPR006`:
43+
44+
> warning ASPDEPR006: ActionContextAccessor is obsolete and will be removed in a future version. For more information, visit <https://aka.ms/aspnet/deprecate/006>.
45+
46+
## Type of breaking change
47+
48+
This change can affect [source compatibility](../../categories.md#source-compatibility).
49+
50+
## Reason for change
51+
52+
With the introduction of endpoint routing in ASP.NET Core, `IActionContextAccessor` is no longer necessary. The endpoint routing infrastructure provides a cleaner, more direct way to access endpoint metadata through `HttpContext.GetEndpoint()`, aligning with ASP.NET Core's architectural evolution toward endpoint routing.
53+
54+
## Recommended action
55+
56+
Migrate from `IActionContextAccessor` to <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> and use `HttpContext.GetEndpoint()`:
57+
58+
Before:
59+
60+
```csharp
61+
public class MyService
62+
{
63+
private readonly IActionContextAccessor _actionContextAccessor;
64+
65+
public MyService(IActionContextAccessor actionContextAccessor)
66+
{
67+
_actionContextAccessor = actionContextAccessor;
68+
}
69+
70+
public void DoSomething()
71+
{
72+
var actionContext = _actionContextAccessor.ActionContext;
73+
var actionDescriptor = actionContext?.ActionDescriptor;
74+
// Use action descriptor metadata
75+
}
76+
}
77+
```
78+
79+
After:
80+
81+
```csharp
82+
public class MyService
83+
{
84+
private readonly IHttpContextAccessor _httpContextAccessor;
85+
86+
public MyService(IHttpContextAccessor httpContextAccessor)
87+
{
88+
_httpContextAccessor = httpContextAccessor;
89+
}
90+
91+
public void DoSomething()
92+
{
93+
var httpContext = _httpContextAccessor.HttpContext;
94+
var endpoint = httpContext?.GetEndpoint();
95+
var actionDescriptor = endpoint?.Metadata.GetMetadata<ActionDescriptor>();
96+
// Use action descriptor metadata.
97+
}
98+
}
99+
```
100+
101+
## Affected APIs
102+
103+
- <xref:Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor?displayProperty=fullName>
104+
- <xref:Microsoft.AspNetCore.Mvc.Infrastructure.ActionContextAccessor?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ items:
1010
href: 10.0.md
1111
- name: ASP.NET Core
1212
items:
13+
- name: IActionContextAccessor and ActionContextAccessor are obsolete
14+
href: aspnet-core/10/iactioncontextaccessor-obsolete.md
1315
- name: IncludeOpenAPIAnalyzers property and MVC API analyzers are deprecated
1416
href: aspnet-core/10/openapi-analyzers-deprecated.md
1517
- name: Microsoft.Extensions.ApiDescription.Client package deprecated

0 commit comments

Comments
 (0)