Skip to content

Commit 536de2f

Browse files
Deprecate IActionContextAccessor (#62647)
Co-authored-by: captainsafia <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent fff3131 commit 536de2f

25 files changed

+68
-0
lines changed

src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure;
1010
/// <summary>
1111
/// Type that provides access to an <see cref="ActionContext"/>.
1212
/// </summary>
13+
[Obsolete("ActionContextAccessor is obsolete and will be removed in a future version. For more information, visit https://aka.ms/aspnet/deprecate/006.", DiagnosticId = "ASPDEPR006")]
1314
public class ActionContextAccessor : IActionContextAccessor
1415
{
1516
internal static readonly IActionContextAccessor Null = new NullActionContextAccessor();

src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ internal partial class ControllerActionInvoker : ResourceInvoker, IActionInvoker
3030
internal ControllerActionInvoker(
3131
ILogger logger,
3232
DiagnosticListener diagnosticListener,
33+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
3334
IActionContextAccessor actionContextAccessor,
35+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
3436
IActionResultTypeMapper mapper,
3537
ControllerContext controllerContext,
3638
ControllerActionInvokerCacheEntry cacheEntry,

src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ internal sealed class ControllerActionInvokerProvider : IActionInvokerProvider
2323
private readonly ILogger _logger;
2424
private readonly DiagnosticListener _diagnosticListener;
2525
private readonly IActionResultTypeMapper _mapper;
26+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
2627
private readonly IActionContextAccessor _actionContextAccessor;
28+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
2729

2830
public ControllerActionInvokerProvider(
2931
ControllerActionInvokerCache controllerActionInvokerCache,
@@ -41,7 +43,9 @@ public ControllerActionInvokerProvider(
4143
ILoggerFactory loggerFactory,
4244
DiagnosticListener diagnosticListener,
4345
IActionResultTypeMapper mapper,
46+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
4447
IActionContextAccessor? actionContextAccessor)
48+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
4549
{
4650
_controllerActionInvokerCache = controllerActionInvokerCache;
4751
_valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
@@ -51,7 +55,9 @@ public ControllerActionInvokerProvider(
5155
_logger = loggerFactory.CreateLogger(typeof(ControllerActionInvoker));
5256
_diagnosticListener = diagnosticListener;
5357
_mapper = mapper;
58+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
5459
_actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
60+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
5561
}
5662

5763
public int Order => -1000;

src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure;
1010
/// <summary>
1111
/// Defines an interface for exposing an <see cref="ActionContext"/>.
1212
/// </summary>
13+
[Obsolete("IActionContextAccessor is obsolete and will be removed in a future version. For more information, visit https://aka.ms/aspnet/deprecate/006.", DiagnosticId = "ASPDEPR006")]
1314
public interface IActionContextAccessor
1415
{
1516
/// <summary>

src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ internal abstract partial class ResourceInvoker
1515
{
1616
protected readonly DiagnosticListener _diagnosticListener;
1717
protected readonly ILogger _logger;
18+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
1819
protected readonly IActionContextAccessor _actionContextAccessor;
20+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
1921
protected readonly IActionResultTypeMapper _mapper;
2022
protected readonly ActionContext _actionContext;
2123
protected readonly IFilterMetadata[] _filters;
@@ -37,7 +39,9 @@ internal abstract partial class ResourceInvoker
3739
public ResourceInvoker(
3840
DiagnosticListener diagnosticListener,
3941
ILogger logger,
42+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
4043
IActionContextAccessor actionContextAccessor,
44+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
4145
IActionResultTypeMapper mapper,
4246
ActionContext actionContext,
4347
IFilterMetadata[] filters,

src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ internal sealed class ControllerRequestDelegateFactory : IRequestDelegateFactory
2424
private readonly ILogger _logger;
2525
private readonly DiagnosticListener _diagnosticListener;
2626
private readonly IActionResultTypeMapper _mapper;
27+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
2728
private readonly IActionContextAccessor _actionContextAccessor;
29+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
2830
private readonly bool _enableActionInvokers;
2931

3032
public ControllerRequestDelegateFactory(
@@ -43,7 +45,9 @@ public ControllerRequestDelegateFactory(
4345
ILoggerFactory loggerFactory,
4446
DiagnosticListener diagnosticListener,
4547
IActionResultTypeMapper mapper,
48+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
4649
IActionContextAccessor? actionContextAccessor)
50+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
4751
{
4852
_controllerActionInvokerCache = controllerActionInvokerCache;
4953
_valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
@@ -54,7 +58,9 @@ public ControllerRequestDelegateFactory(
5458
_logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
5559
_diagnosticListener = diagnosticListener;
5660
_mapper = mapper;
61+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
5762
_actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
63+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
5864
}
5965

6066
public RequestDelegate? CreateRequestDelegate(ActionDescriptor actionDescriptor, RouteValueDictionary? dataTokens)

src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ public TestControllerActionInvoker(
398398
: base(
399399
logger,
400400
diagnosticListener,
401+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
401402
ActionContextAccessor.Null,
403+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
402404
mapper,
403405
CreateControllerContext(actionContext, valueProviderFactories, maxAllowedErrorsInModelState),
404406
CreateCacheEntry((ControllerActionDescriptor)actionContext.ActionDescriptor, controllerFactory),

src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,9 @@ public async Task Invoke_UsesDefaultValuesIfNotBound()
14321432
var invoker = new ControllerActionInvoker(
14331433
new NullLoggerFactory().CreateLogger<ControllerActionInvoker>(),
14341434
new DiagnosticListener("Microsoft.AspNetCore"),
1435+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
14351436
ActionContextAccessor.Null,
1437+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
14361438
new ActionResultTypeMapper(),
14371439
controllerContext,
14381440
cacheEntry,
@@ -1769,7 +1771,9 @@ private ControllerActionInvoker CreateInvoker(
17691771
var invoker = new ControllerActionInvoker(
17701772
logger,
17711773
diagnosticSource,
1774+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
17721775
ActionContextAccessor.Null,
1776+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
17731777
new ActionResultTypeMapper(),
17741778
controllerContext,
17751779
cacheEntry,

src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public PageActionInvoker(
3535
IPageHandlerMethodSelector handlerMethodSelector,
3636
DiagnosticListener diagnosticListener,
3737
ILogger logger,
38+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
3839
IActionContextAccessor actionContextAccessor,
40+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
3941
IActionResultTypeMapper mapper,
4042
PageContext pageContext,
4143
IFilterMetadata[] filterMetadata,

src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ internal sealed class PageActionInvokerProvider : IActionInvokerProvider
2525
private readonly DiagnosticListener _diagnosticListener;
2626
private readonly ILogger<PageActionInvoker> _logger;
2727
private readonly IActionResultTypeMapper _mapper;
28+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
2829
private readonly IActionContextAccessor _actionContextAccessor;
30+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
2931

3032
public PageActionInvokerProvider(
3133
PageLoader pageLoader,
@@ -38,7 +40,9 @@ public PageActionInvokerProvider(
3840
DiagnosticListener diagnosticListener,
3941
ILoggerFactory loggerFactory,
4042
IActionResultTypeMapper mapper,
43+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
4144
IActionContextAccessor? actionContextAccessor = null)
45+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
4246
{
4347
_pageLoader = pageLoader;
4448
_pageActionInvokerCache = pageActionInvokerCache;
@@ -50,7 +54,9 @@ public PageActionInvokerProvider(
5054
_diagnosticListener = diagnosticListener;
5155
_logger = loggerFactory.CreateLogger<PageActionInvoker>();
5256
_mapper = mapper;
57+
#pragma warning disable ASPDEPR006 // Type or member is obsolete
5358
_actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
59+
#pragma warning restore ASPDEPR006 // Type or member is obsolete
5460
}
5561

5662
// For testing

0 commit comments

Comments
 (0)