From ac6e05acee565aaccadcdec793862386e9c1ce81 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 9 Jul 2025 23:33:14 +0000 Subject: [PATCH 1/7] Initial plan From 6ecda203f54d0ae80baef9022357077734b95881 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 9 Jul 2025 23:54:57 +0000 Subject: [PATCH 2/7] Add obsolete attributes to IActionContextAccessor and suppress warnings in framework code Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com> --- .../Mvc.Core/src/Infrastructure/ActionContextAccessor.cs | 1 + .../Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs | 2 ++ .../src/Infrastructure/ControllerActionInvokerProvider.cs | 6 ++++++ .../Mvc.Core/src/Infrastructure/IActionContextAccessor.cs | 1 + src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs | 4 ++++ .../src/Routing/ControllerRequestDelegateFactory.cs | 6 ++++++ src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs | 2 ++ .../test/Infrastructure/ControllerActionInvokerTest.cs | 4 ++++ .../Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs | 2 ++ .../src/Infrastructure/PageActionInvokerProvider.cs | 6 ++++++ .../src/Infrastructure/PageRequestDelegateFactory.cs | 6 ++++++ 11 files changed, 40 insertions(+) diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs index 5a8213ef9ce2..1a05a370fb58 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs @@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Type that provides access to an . /// +[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(); diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs index 8aef2b4dd2e6..b0364898b3fa 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs @@ -30,7 +30,9 @@ 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, diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs index 24b6395038bc..e6f3077fdb55 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs @@ -23,7 +23,9 @@ 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, @@ -41,7 +43,9 @@ public ControllerActionInvokerProvider( 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(); @@ -51,7 +55,9 @@ 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; diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs index e4ebd8f65a07..05e360213f54 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs @@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Defines an interface for exposing an . /// +[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 { /// diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs index f09da93f3c3f..0df19d091551 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs @@ -15,7 +15,9 @@ 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; @@ -37,7 +39,9 @@ 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, diff --git a/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs b/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs index f31448e78732..eefffed548d1 100644 --- a/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs +++ b/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs @@ -24,7 +24,9 @@ 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( @@ -43,7 +45,9 @@ public ControllerRequestDelegateFactory( 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(); @@ -54,7 +58,9 @@ public ControllerRequestDelegateFactory( _logger = loggerFactory.CreateLogger(); _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) diff --git a/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs b/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs index 9816a5deb6ec..9361a0802426 100644 --- a/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs +++ b/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs @@ -398,7 +398,9 @@ 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), diff --git a/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs b/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs index 225bb6a407f1..fc141e53827c 100644 --- a/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs +++ b/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs @@ -1432,7 +1432,9 @@ public async Task Invoke_UsesDefaultValuesIfNotBound() var invoker = new ControllerActionInvoker( new NullLoggerFactory().CreateLogger(), 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, @@ -1769,7 +1771,9 @@ 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, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs index 6ad0d6faa2b4..c2305e3b4d5b 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs @@ -35,7 +35,9 @@ 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, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs index 19f9ff1c7da8..7f630a4b589d 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs @@ -25,7 +25,9 @@ internal sealed class PageActionInvokerProvider : IActionInvokerProvider private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _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, @@ -38,7 +40,9 @@ public PageActionInvokerProvider( 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 { _pageLoader = pageLoader; _pageActionInvokerCache = pageActionInvokerCache; @@ -50,7 +54,9 @@ public PageActionInvokerProvider( _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _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 diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs index e6c19ea66350..e691f5726904 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs @@ -26,7 +26,9 @@ internal sealed class PageRequestDelegateFactory : IRequestDelegateFactory private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _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( @@ -53,7 +55,9 @@ public PageRequestDelegateFactory( 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(); @@ -65,7 +69,9 @@ public PageRequestDelegateFactory( _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _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) From 8e5a837574850cc691d5fd7e88226b5fbb5edde5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 10 Jul 2025 00:01:13 +0000 Subject: [PATCH 3/7] Suppress obsolete warnings in test files and websites that use deprecated IActionContextAccessor Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com> --- .../Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs | 2 ++ src/Mvc/test/WebSites/BasicWebSite/Startup.cs | 2 ++ .../test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs | 2 ++ src/Mvc/test/WebSites/Common/TestResponseGenerator.cs | 2 ++ src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs | 2 ++ src/Mvc/test/WebSites/RoutingWebSite/Startup.cs | 2 ++ src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs | 2 ++ src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs | 2 ++ .../test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs | 2 ++ src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs | 2 ++ src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs | 2 ++ src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs | 2 ++ .../WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs | 2 ++ src/Mvc/test/WebSites/VersioningWebSite/Startup.cs | 2 ++ 14 files changed, 28 insertions(+) diff --git a/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs b/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs index 3ed467facee4..64c6df00b877 100644 --- a/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs +++ b/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs @@ -1565,7 +1565,9 @@ 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(), diff --git a/src/Mvc/test/WebSites/BasicWebSite/Startup.cs b/src/Mvc/test/WebSites/BasicWebSite/Startup.cs index 1a9fb3200c0e..f785a70c8119 100644 --- a/src/Mvc/test/WebSites/BasicWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/BasicWebSite/Startup.cs @@ -20,7 +20,9 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor(); services.AddScoped(); services.AddScoped(); + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs b/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs index 94a467baa003..936e6d7d9a3a 100644 --- a/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs +++ b/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs @@ -49,7 +49,9 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddTransient(); services.AddScoped(); + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete services.TryAddSingleton(CreateWeatherForecastService); } diff --git a/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs b/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs index b447d97f287f..532a36039800 100644 --- a/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs +++ b/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs @@ -12,7 +12,9 @@ public class TestResponseGenerator { private readonly ActionContext _actionContext; +#pragma warning disable CS0618 // Type or member is obsolete public TestResponseGenerator(IActionContextAccessor contextAccessor) +#pragma warning restore CS0618 // Type or member is obsolete { _actionContext = contextAccessor.ActionContext; if (_actionContext == null) diff --git a/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs b/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs index 60fe3c2ce951..254c874db7c5 100644 --- a/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs @@ -23,7 +23,9 @@ public void ConfigureServices(IServiceCollection services) services.AddLogging(); services.AddHttpContextAccessor(); services.AddScoped(); + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs b/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs index 9438fe0195cb..fcfa9e9dc1c1 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs @@ -29,7 +29,9 @@ public void ConfigureServices(IServiceCollection services) ConfigureRoutingServices(services); services.AddScoped(); + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs index 4dc4d13e07c2..969d60fd3167 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs @@ -18,7 +18,9 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient(); services.AddScoped(); + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs index 840c50ce64b7..7e53b240ee8a 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs @@ -33,7 +33,9 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient(); services.AddScoped(); + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs index 268c19d75f7c..5edc07308bab 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs @@ -17,7 +17,9 @@ public void ConfigureServices(IServiceCollection services) services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); services.AddScoped(); // This is used by test response generator + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs index 9fd809a7ea6c..8f4ee7c4034b 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs @@ -16,7 +16,9 @@ public void ConfigureServices(IServiceCollection services) .AddNewtonsoftJson(); services.AddScoped(); + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs index 889c18b40f7a..66ad04a9b866 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs @@ -17,7 +17,9 @@ public void ConfigureServices(IServiceCollection services) services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); services.AddScoped(); // This is used by test response generator + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs index d9e38eac752b..6401d9710c17 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs @@ -31,7 +31,9 @@ public void ConfigureServices(IServiceCollection services) }); services.AddScoped(); + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs index afcc67cecfc3..0a1f2a3d15a9 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs @@ -31,7 +31,9 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); // This is used by test response generator + #pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete services.AddSingleton(); } diff --git a/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs b/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs index f4a02003c92f..81a281fbabdc 100644 --- a/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs @@ -14,7 +14,9 @@ public void ConfigureServices(IServiceCollection services) .AddNewtonsoftJson(); services.AddScoped(); +#pragma warning disable CS0618 // Type or member is obsolete services.AddSingleton(); +#pragma warning restore CS0618 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) From 843dfd33f9fd01e727ce44affc2efd10668e2927 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 00:05:36 +0000 Subject: [PATCH 4/7] Replace IActionContextAccessor with IHttpContextAccessor throughout the codebase Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com> --- .../Infrastructure/ActionContextAccessor.cs | 1 - .../Infrastructure/ControllerActionInvoker.cs | 5 +-- .../ControllerActionInvokerProvider.cs | 20 --------- .../Infrastructure/IActionContextAccessor.cs | 1 - .../src/Infrastructure/ResourceInvoker.cs | 9 ---- .../ControllerRequestDelegateFactory.cs | 20 --------- .../test/Filters/MiddlewareFilterTest.cs | 3 -- .../ControllerActionInvokerTest.cs | 6 --- .../src/Infrastructure/PageActionInvoker.cs | 4 -- .../PageActionInvokerProvider.cs | 12 +---- .../PageRequestDelegateFactory.cs | 24 ---------- .../Infrastructure/PageActionInvokerTest.cs | 3 -- src/Mvc/test/WebSites/BasicWebSite/Startup.cs | 3 -- .../StartupWithoutEndpointRouting.cs | 3 -- .../WebSites/Common/TestResponseGenerator.cs | 45 +++++++++++-------- .../WebSites/GenericHostWebSite/Startup.cs | 3 -- .../test/WebSites/RoutingWebSite/Startup.cs | 4 +- .../RoutingWebSite/StartupForDynamic.cs | 4 +- .../RoutingWebSite/StartupForDynamicOrder.cs | 4 +- .../StartupForEndpointFilters.cs | 4 +- .../RoutingWebSite/StartupForFallback.cs | 4 +- .../RoutingWebSite/StartupForGroups.cs | 4 +- .../RoutingWebSite/StartupForLinkGenerator.cs | 4 +- .../StartupRoutingDifferentBranches.cs | 4 +- .../WebSites/VersioningWebSite/Startup.cs | 4 +- 25 files changed, 38 insertions(+), 160 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs index 1a05a370fb58..5a8213ef9ce2 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs @@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Type that provides access to an . /// -[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(); diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs index b0364898b3fa..edf38e7789d7 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs @@ -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); diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs index e6f3077fdb55..a9d56ddd2505 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs @@ -23,9 +23,6 @@ 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, @@ -33,19 +30,6 @@ public ControllerActionInvokerProvider( ILoggerFactory loggerFactory, DiagnosticListener diagnosticListener, IActionResultTypeMapper mapper) - : this(controllerActionInvokerCache, optionsAccessor, loggerFactory, diagnosticListener, mapper, null) - { - } - - public ControllerActionInvokerProvider( - ControllerActionInvokerCache controllerActionInvokerCache, - IOptions 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(); @@ -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; @@ -83,7 +64,6 @@ public void OnProvidersExecuting(ActionInvokerProviderContext context) var invoker = new ControllerActionInvoker( _logger, _diagnosticListener, - _actionContextAccessor, _mapper, controllerContext, cacheEntry, diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs index 05e360213f54..e4ebd8f65a07 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs @@ -10,7 +10,6 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Defines an interface for exposing an . /// -[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 { /// diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs index 0df19d091551..6764a25c5178 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs @@ -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; @@ -39,9 +36,6 @@ 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, @@ -49,7 +43,6 @@ public ResourceInvoker( { _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)); @@ -65,7 +58,6 @@ public virtual Task InvokeAsync() return Logged(this); } - _actionContextAccessor.ActionContext = _actionContext; var scope = _logger.ActionScope(_actionContext.ActionDescriptor); Task task; @@ -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; diff --git a/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs b/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs index eefffed548d1..ccd75be935a9 100644 --- a/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs +++ b/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs @@ -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( @@ -35,19 +32,6 @@ public ControllerRequestDelegateFactory( ILoggerFactory loggerFactory, DiagnosticListener diagnosticListener, IActionResultTypeMapper mapper) - : this(controllerActionInvokerCache, optionsAccessor, loggerFactory, diagnosticListener, mapper, null) - { - } - - public ControllerRequestDelegateFactory( - ControllerActionInvokerCache controllerActionInvokerCache, - IOptions 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(); @@ -58,9 +42,6 @@ public ControllerRequestDelegateFactory( _logger = loggerFactory.CreateLogger(); _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) @@ -100,7 +81,6 @@ public ControllerRequestDelegateFactory( var invoker = new ControllerActionInvoker( _logger, _diagnosticListener, - _actionContextAccessor, _mapper, controllerContext, cacheEntry, diff --git a/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs b/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs index 9361a0802426..eea690b84a91 100644 --- a/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs +++ b/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs @@ -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), diff --git a/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs b/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs index fc141e53827c..514214b029e9 100644 --- a/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs +++ b/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs @@ -1432,9 +1432,6 @@ public async Task Invoke_UsesDefaultValuesIfNotBound() var invoker = new ControllerActionInvoker( new NullLoggerFactory().CreateLogger(), 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, @@ -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, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs index c2305e3b4d5b..98baa97ad429 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs @@ -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, @@ -47,7 +44,6 @@ public PageActionInvoker( : base( diagnosticListener, logger, - actionContextAccessor, mapper, pageContext, filterMetadata, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs index 7f630a4b589d..eed901c77f4e 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs @@ -25,9 +25,6 @@ internal sealed class PageActionInvokerProvider : IActionInvokerProvider private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _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, @@ -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; @@ -54,9 +48,6 @@ public PageActionInvokerProvider( _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _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 @@ -96,7 +87,6 @@ public void OnProvidersExecuting(ActionInvokerProviderContext context) _selector, _diagnosticListener, _logger, - _actionContextAccessor, _mapper, pageContext, filters, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs index e691f5726904..6dd11e946119 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs @@ -26,9 +26,6 @@ internal sealed class PageRequestDelegateFactory : IRequestDelegateFactory private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _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( @@ -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, - IOptions 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(); @@ -69,9 +49,6 @@ public PageRequestDelegateFactory( _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _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) @@ -109,7 +86,6 @@ public PageRequestDelegateFactory( _selector, _diagnosticListener, _logger, - _actionContextAccessor, _mapper, pageContext, filters, diff --git a/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs b/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs index 64c6df00b877..1f49de899edb 100644 --- a/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs +++ b/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs @@ -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(), diff --git a/src/Mvc/test/WebSites/BasicWebSite/Startup.cs b/src/Mvc/test/WebSites/BasicWebSite/Startup.cs index f785a70c8119..0b00d3b0736d 100644 --- a/src/Mvc/test/WebSites/BasicWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/BasicWebSite/Startup.cs @@ -20,9 +20,6 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor(); services.AddScoped(); services.AddScoped(); - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs b/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs index 936e6d7d9a3a..6e3315cfa692 100644 --- a/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs +++ b/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs @@ -49,9 +49,6 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddTransient(); services.AddScoped(); - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete services.TryAddSingleton(CreateWeatherForecastService); } diff --git a/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs b/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs index 532a36039800..bf34e8187c34 100644 --- a/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs +++ b/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs @@ -10,53 +10,62 @@ namespace Microsoft.AspNetCore.Mvc; // Generates a response based on the expected URL and action context public class TestResponseGenerator { - private readonly ActionContext _actionContext; + private readonly IHttpContextAccessor _httpContextAccessor; -#pragma warning disable CS0618 // Type or member is obsolete - public TestResponseGenerator(IActionContextAccessor contextAccessor) -#pragma warning restore CS0618 // Type or member is obsolete + public TestResponseGenerator(IHttpContextAccessor httpContextAccessor) { - _actionContext = contextAccessor.ActionContext; - if (_actionContext == null) + _httpContextAccessor = httpContextAccessor; + if (_httpContextAccessor.HttpContext == null) { - throw new InvalidOperationException("ActionContext should not be null here."); + throw new InvalidOperationException("HttpContext should not be null here."); } } public ActionResult Generate(params string[] expectedUrls) { + var httpContext = _httpContextAccessor.HttpContext!; var link = (string)null; - var query = _actionContext.HttpContext.Request.Query; + var query = httpContext.Request.Query; if (query.ContainsKey("link")) { var values = query .Where(kvp => kvp.Key != "link" && kvp.Key != "link_action" && kvp.Key != "link_controller") .ToDictionary(kvp => kvp.Key.Substring("link_".Length), kvp => (object)kvp.Value[0]); - var urlHelper = GetUrlHelper(_actionContext); + var urlHelper = GetUrlHelper(httpContext); link = urlHelper.Action(query["link_action"], query["link_controller"], values); } - var attributeRoutingInfo = _actionContext.ActionDescriptor.AttributeRouteInfo; + var endpoint = httpContext.GetEndpoint(); + var actionDescriptor = endpoint?.Metadata.GetMetadata(); + var attributeRoutingInfo = actionDescriptor?.AttributeRouteInfo; return new OkObjectResult(new { expectedUrls = expectedUrls, - actualUrl = _actionContext.HttpContext.Request.Path.Value, - routeName = attributeRoutingInfo == null ? null : attributeRoutingInfo.Name, - routeValues = new Dictionary(_actionContext.RouteData.Values), + actualUrl = httpContext.Request.Path.Value, + routeName = attributeRoutingInfo?.Name, + routeValues = new Dictionary(httpContext.GetRouteData().Values), - action = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ActionName, - controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerName, + action = actionDescriptor?.ActionName, + controller = actionDescriptor?.ControllerName, link, }); } - private IUrlHelper GetUrlHelper(ActionContext context) + private IUrlHelper GetUrlHelper(HttpContext httpContext) { - var services = context.HttpContext.RequestServices; - var urlHelper = services.GetRequiredService().GetUrlHelper(context); + var services = httpContext.RequestServices; + var urlHelperFactory = services.GetRequiredService(); + + // Create ActionContext from HttpContext for URL generation + var actionContext = new ActionContext( + httpContext, + httpContext.GetRouteData(), + httpContext.GetEndpoint()?.Metadata.GetMetadata() ?? new ControllerActionDescriptor()); + + var urlHelper = urlHelperFactory.GetUrlHelper(actionContext); return urlHelper; } } diff --git a/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs b/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs index 254c874db7c5..1389499563e6 100644 --- a/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs @@ -23,9 +23,6 @@ public void ConfigureServices(IServiceCollection services) services.AddLogging(); services.AddHttpContextAccessor(); services.AddScoped(); - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs b/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs index fcfa9e9dc1c1..c0f41ce45af1 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs @@ -28,10 +28,8 @@ public void ConfigureServices(IServiceCollection services) ConfigureRoutingServices(services); + services.AddHttpContextAccessor(); services.AddScoped(); - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs index 969d60fd3167..10a607d09c54 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs @@ -17,10 +17,8 @@ public void ConfigureServices(IServiceCollection services) .AddNewtonsoftJson(); services.AddTransient(); + services.AddHttpContextAccessor(); services.AddScoped(); - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs index 7e53b240ee8a..883d71eb490a 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs @@ -32,10 +32,8 @@ public void ConfigureServices(IServiceCollection services) .AddNewtonsoftJson(); services.AddTransient(); + services.AddHttpContextAccessor(); services.AddScoped(); - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs index 5edc07308bab..ae7813ff329c 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs @@ -15,11 +15,9 @@ public void ConfigureServices(IServiceCollection services) // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); + services.AddHttpContextAccessor(); services.AddScoped(); // This is used by test response generator - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs index 8f4ee7c4034b..f1a16bab229f 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs @@ -15,10 +15,8 @@ public void ConfigureServices(IServiceCollection services) .AddMvc() .AddNewtonsoftJson(); + services.AddHttpContextAccessor(); services.AddScoped(); - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs index 66ad04a9b866..446084cfe353 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs @@ -15,11 +15,9 @@ public void ConfigureServices(IServiceCollection services) // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); + services.AddHttpContextAccessor(); services.AddScoped(); // This is used by test response generator - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs index 6401d9710c17..48bf12784edd 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs @@ -30,10 +30,8 @@ public void ConfigureServices(IServiceCollection services) options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer); }); + services.AddHttpContextAccessor(); services.AddScoped(); - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs index 0a1f2a3d15a9..66dd08542575 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs @@ -29,11 +29,9 @@ public void ConfigureServices(IServiceCollection services) ConfigureRoutingServices(services); + services.AddHttpContextAccessor(); services.AddScoped(); // This is used by test response generator - #pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete services.AddSingleton(); } diff --git a/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs b/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs index 81a281fbabdc..b8c6c33802a8 100644 --- a/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs @@ -13,10 +13,8 @@ public void ConfigureServices(IServiceCollection services) services.AddControllers(ConfigureMvcOptions) .AddNewtonsoftJson(); + services.AddHttpContextAccessor(); services.AddScoped(); -#pragma warning disable CS0618 // Type or member is obsolete - services.AddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) From e2c25f00b759a78082366293c061a34be3599d59 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 15 Jul 2025 00:23:42 +0000 Subject: [PATCH 5/7] Add back obsolete attributes to IActionContextAccessor interface and ActionContextAccessor class Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com> --- src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs | 1 + src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs index 5a8213ef9ce2..7f020cfddc1a 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs @@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Type that provides access to an . /// +[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(); diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs index e4ebd8f65a07..8c4df8ee5c45 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs @@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Defines an interface for exposing an . /// +[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 { /// From da6d7f4585f336a7386dc586be62bb11c5b7aa8c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 18 Jul 2025 03:55:19 +0000 Subject: [PATCH 6/7] Revert framework to use IActionContextAccessor internally with ASPDEPR004 pragma disables Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com> --- .../Infrastructure/ActionContextAccessor.cs | 2 +- .../Infrastructure/ControllerActionInvoker.cs | 5 ++- .../ControllerActionInvokerProvider.cs | 20 +++++++++ .../Infrastructure/IActionContextAccessor.cs | 2 +- .../src/Infrastructure/ResourceInvoker.cs | 9 ++++ .../ControllerRequestDelegateFactory.cs | 20 +++++++++ .../test/Filters/MiddlewareFilterTest.cs | 3 ++ .../ControllerActionInvokerTest.cs | 6 +++ .../src/Infrastructure/PageActionInvoker.cs | 4 ++ .../PageActionInvokerProvider.cs | 12 ++++- .../PageRequestDelegateFactory.cs | 24 ++++++++++ .../Infrastructure/PageActionInvokerTest.cs | 3 ++ src/Mvc/test/WebSites/BasicWebSite/Startup.cs | 3 ++ .../StartupWithoutEndpointRouting.cs | 3 ++ .../WebSites/Common/TestResponseGenerator.cs | 45 ++++++++----------- .../WebSites/GenericHostWebSite/Startup.cs | 3 ++ .../test/WebSites/RoutingWebSite/Startup.cs | 4 +- .../RoutingWebSite/StartupForDynamic.cs | 4 +- .../RoutingWebSite/StartupForDynamicOrder.cs | 4 +- .../StartupForEndpointFilters.cs | 4 +- .../RoutingWebSite/StartupForFallback.cs | 4 +- .../RoutingWebSite/StartupForGroups.cs | 4 +- .../RoutingWebSite/StartupForLinkGenerator.cs | 4 +- .../StartupRoutingDifferentBranches.cs | 4 +- .../WebSites/VersioningWebSite/Startup.cs | 4 +- 25 files changed, 160 insertions(+), 40 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs index 7f020cfddc1a..3003544470d5 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Type that provides access to an . /// -[Obsolete("ActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version.")] +[Obsolete("ActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version.", DiagnosticId = "ASPDEPR004")] public class ActionContextAccessor : IActionContextAccessor { internal static readonly IActionContextAccessor Null = new NullActionContextAccessor(); diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs index edf38e7789d7..f3b46308cc98 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs @@ -30,11 +30,14 @@ internal partial class ControllerActionInvoker : ResourceInvoker, IActionInvoker internal ControllerActionInvoker( ILogger logger, DiagnosticListener diagnosticListener, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + IActionContextAccessor actionContextAccessor, +#pragma warning restore ASPDEPR004 // Type or member is obsolete IActionResultTypeMapper mapper, ControllerContext controllerContext, ControllerActionInvokerCacheEntry cacheEntry, IFilterMetadata[] filters) - : base(diagnosticListener, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories) + : base(diagnosticListener, logger, actionContextAccessor, mapper, controllerContext, filters, controllerContext.ValueProviderFactories) { ArgumentNullException.ThrowIfNull(cacheEntry); diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs index a9d56ddd2505..c65cdba1426b 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs @@ -23,6 +23,9 @@ internal sealed class ControllerActionInvokerProvider : IActionInvokerProvider private readonly ILogger _logger; private readonly DiagnosticListener _diagnosticListener; private readonly IActionResultTypeMapper _mapper; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + private readonly IActionContextAccessor _actionContextAccessor; +#pragma warning restore ASPDEPR004 // Type or member is obsolete public ControllerActionInvokerProvider( ControllerActionInvokerCache controllerActionInvokerCache, @@ -30,6 +33,19 @@ public ControllerActionInvokerProvider( ILoggerFactory loggerFactory, DiagnosticListener diagnosticListener, IActionResultTypeMapper mapper) + : this(controllerActionInvokerCache, optionsAccessor, loggerFactory, diagnosticListener, mapper, null) + { + } + + public ControllerActionInvokerProvider( + ControllerActionInvokerCache controllerActionInvokerCache, + IOptions optionsAccessor, + ILoggerFactory loggerFactory, + DiagnosticListener diagnosticListener, + IActionResultTypeMapper mapper, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + IActionContextAccessor? actionContextAccessor) +#pragma warning restore ASPDEPR004 // Type or member is obsolete { _controllerActionInvokerCache = controllerActionInvokerCache; _valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray(); @@ -39,6 +55,9 @@ public ControllerActionInvokerProvider( _logger = loggerFactory.CreateLogger(typeof(ControllerActionInvoker)); _diagnosticListener = diagnosticListener; _mapper = mapper; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public int Order => -1000; @@ -64,6 +83,7 @@ public void OnProvidersExecuting(ActionInvokerProviderContext context) var invoker = new ControllerActionInvoker( _logger, _diagnosticListener, + _actionContextAccessor, _mapper, controllerContext, cacheEntry, diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs index 8c4df8ee5c45..0609f62acdb9 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Defines an interface for exposing an . /// -[Obsolete("IActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version.")] +[Obsolete("IActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version.", DiagnosticId = "ASPDEPR004")] public interface IActionContextAccessor { /// diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs index 6764a25c5178..2edeb89ee583 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs @@ -15,6 +15,9 @@ internal abstract partial class ResourceInvoker { protected readonly DiagnosticListener _diagnosticListener; protected readonly ILogger _logger; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + protected readonly IActionContextAccessor _actionContextAccessor; +#pragma warning restore ASPDEPR004 // Type or member is obsolete protected readonly IActionResultTypeMapper _mapper; protected readonly ActionContext _actionContext; protected readonly IFilterMetadata[] _filters; @@ -36,6 +39,9 @@ internal abstract partial class ResourceInvoker public ResourceInvoker( DiagnosticListener diagnosticListener, ILogger logger, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + IActionContextAccessor actionContextAccessor, +#pragma warning restore ASPDEPR004 // Type or member is obsolete IActionResultTypeMapper mapper, ActionContext actionContext, IFilterMetadata[] filters, @@ -43,6 +49,7 @@ public ResourceInvoker( { _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)); @@ -58,6 +65,7 @@ public virtual Task InvokeAsync() return Logged(this); } + _actionContextAccessor.ActionContext = _actionContext; var scope = _logger.ActionScope(_actionContext.ActionDescriptor); Task task; @@ -92,6 +100,7 @@ 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; diff --git a/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs b/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs index ccd75be935a9..5f19dd091b38 100644 --- a/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs +++ b/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs @@ -24,6 +24,9 @@ internal sealed class ControllerRequestDelegateFactory : IRequestDelegateFactory private readonly ILogger _logger; private readonly DiagnosticListener _diagnosticListener; private readonly IActionResultTypeMapper _mapper; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + private readonly IActionContextAccessor _actionContextAccessor; +#pragma warning restore ASPDEPR004 // Type or member is obsolete private readonly bool _enableActionInvokers; public ControllerRequestDelegateFactory( @@ -32,6 +35,19 @@ public ControllerRequestDelegateFactory( ILoggerFactory loggerFactory, DiagnosticListener diagnosticListener, IActionResultTypeMapper mapper) + : this(controllerActionInvokerCache, optionsAccessor, loggerFactory, diagnosticListener, mapper, null) + { + } + + public ControllerRequestDelegateFactory( + ControllerActionInvokerCache controllerActionInvokerCache, + IOptions optionsAccessor, + ILoggerFactory loggerFactory, + DiagnosticListener diagnosticListener, + IActionResultTypeMapper mapper, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + IActionContextAccessor? actionContextAccessor) +#pragma warning restore ASPDEPR004 // Type or member is obsolete { _controllerActionInvokerCache = controllerActionInvokerCache; _valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray(); @@ -42,6 +58,9 @@ public ControllerRequestDelegateFactory( _logger = loggerFactory.CreateLogger(); _diagnosticListener = diagnosticListener; _mapper = mapper; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public RequestDelegate? CreateRequestDelegate(ActionDescriptor actionDescriptor, RouteValueDictionary? dataTokens) @@ -81,6 +100,7 @@ public ControllerRequestDelegateFactory( var invoker = new ControllerActionInvoker( _logger, _diagnosticListener, + _actionContextAccessor, _mapper, controllerContext, cacheEntry, diff --git a/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs b/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs index eea690b84a91..596befca5274 100644 --- a/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs +++ b/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs @@ -398,6 +398,9 @@ public TestControllerActionInvoker( : base( logger, diagnosticListener, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + ActionContextAccessor.Null, +#pragma warning restore ASPDEPR004 // Type or member is obsolete mapper, CreateControllerContext(actionContext, valueProviderFactories, maxAllowedErrorsInModelState), CreateCacheEntry((ControllerActionDescriptor)actionContext.ActionDescriptor, controllerFactory), diff --git a/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs b/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs index 514214b029e9..67099d6740ec 100644 --- a/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs +++ b/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs @@ -1432,6 +1432,9 @@ public async Task Invoke_UsesDefaultValuesIfNotBound() var invoker = new ControllerActionInvoker( new NullLoggerFactory().CreateLogger(), new DiagnosticListener("Microsoft.AspNetCore"), +#pragma warning disable ASPDEPR004 // Type or member is obsolete + ActionContextAccessor.Null, +#pragma warning restore ASPDEPR004 // Type or member is obsolete new ActionResultTypeMapper(), controllerContext, cacheEntry, @@ -1768,6 +1771,9 @@ private ControllerActionInvoker CreateInvoker( var invoker = new ControllerActionInvoker( logger, diagnosticSource, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + ActionContextAccessor.Null, +#pragma warning restore ASPDEPR004 // Type or member is obsolete new ActionResultTypeMapper(), controllerContext, cacheEntry, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs index 98baa97ad429..f2f36c7007f1 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs @@ -35,6 +35,9 @@ public PageActionInvoker( IPageHandlerMethodSelector handlerMethodSelector, DiagnosticListener diagnosticListener, ILogger logger, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + IActionContextAccessor actionContextAccessor, +#pragma warning restore ASPDEPR004 // Type or member is obsolete IActionResultTypeMapper mapper, PageContext pageContext, IFilterMetadata[] filterMetadata, @@ -44,6 +47,7 @@ public PageActionInvoker( : base( diagnosticListener, logger, + actionContextAccessor, mapper, pageContext, filterMetadata, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs index eed901c77f4e..27658149617b 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs @@ -25,6 +25,9 @@ internal sealed class PageActionInvokerProvider : IActionInvokerProvider private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _logger; private readonly IActionResultTypeMapper _mapper; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + private readonly IActionContextAccessor _actionContextAccessor; +#pragma warning restore ASPDEPR004 // Type or member is obsolete public PageActionInvokerProvider( PageLoader pageLoader, @@ -36,7 +39,10 @@ public PageActionInvokerProvider( IPageHandlerMethodSelector selector, DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory, - IActionResultTypeMapper mapper) + IActionResultTypeMapper mapper, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + IActionContextAccessor? actionContextAccessor = null) +#pragma warning restore ASPDEPR004 // Type or member is obsolete { _pageLoader = pageLoader; _pageActionInvokerCache = pageActionInvokerCache; @@ -48,6 +54,9 @@ public PageActionInvokerProvider( _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _mapper = mapper; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; +#pragma warning restore ASPDEPR004 // Type or member is obsolete } // For testing @@ -87,6 +96,7 @@ public void OnProvidersExecuting(ActionInvokerProviderContext context) _selector, _diagnosticListener, _logger, + _actionContextAccessor, _mapper, pageContext, filters, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs index 6dd11e946119..d5f6ff007918 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs @@ -26,6 +26,9 @@ internal sealed class PageRequestDelegateFactory : IRequestDelegateFactory private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _logger; private readonly IActionResultTypeMapper _mapper; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + private readonly IActionContextAccessor _actionContextAccessor; +#pragma warning restore ASPDEPR004 // Type or member is obsolete private readonly bool _enableActionInvokers; public PageRequestDelegateFactory( @@ -38,6 +41,23 @@ 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, + IOptions mvcViewOptions, + IPageHandlerMethodSelector selector, + DiagnosticListener diagnosticListener, + ILoggerFactory loggerFactory, + IActionResultTypeMapper mapper, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + IActionContextAccessor? actionContextAccessor) +#pragma warning restore ASPDEPR004 // Type or member is obsolete { _cache = cache; _valueProviderFactories = mvcOptions.Value.ValueProviderFactories.ToArray(); @@ -49,6 +69,9 @@ public PageRequestDelegateFactory( _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _mapper = mapper; +#pragma warning disable ASPDEPR004 // Type or member is obsolete + _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public RequestDelegate? CreateRequestDelegate(ActionDescriptor actionDescriptor, RouteValueDictionary? dataTokens) @@ -86,6 +109,7 @@ public PageRequestDelegateFactory( _selector, _diagnosticListener, _logger, + _actionContextAccessor, _mapper, pageContext, filters, diff --git a/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs b/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs index 1f49de899edb..6a64e7993aac 100644 --- a/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs +++ b/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs @@ -1565,6 +1565,9 @@ object pageFactory(PageContext context, ViewContext viewContext) selector.Object, diagnosticListener ?? new DiagnosticListener("Microsoft.AspNetCore"), logger ?? NullLogger.Instance, +#pragma warning disable ASPDEPR004 // Type or member is obsolete + ActionContextAccessor.Null, +#pragma warning restore ASPDEPR004 // Type or member is obsolete new ActionResultTypeMapper(), pageContext, filters ?? Array.Empty(), diff --git a/src/Mvc/test/WebSites/BasicWebSite/Startup.cs b/src/Mvc/test/WebSites/BasicWebSite/Startup.cs index 0b00d3b0736d..df7f17b1b356 100644 --- a/src/Mvc/test/WebSites/BasicWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/BasicWebSite/Startup.cs @@ -20,6 +20,9 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor(); services.AddScoped(); services.AddScoped(); + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs b/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs index 6e3315cfa692..b9f319db2fc9 100644 --- a/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs +++ b/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs @@ -49,6 +49,9 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddTransient(); services.AddScoped(); + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete services.TryAddSingleton(CreateWeatherForecastService); } diff --git a/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs b/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs index bf34e8187c34..d254fbf46474 100644 --- a/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs +++ b/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs @@ -10,62 +10,53 @@ namespace Microsoft.AspNetCore.Mvc; // Generates a response based on the expected URL and action context public class TestResponseGenerator { - private readonly IHttpContextAccessor _httpContextAccessor; + private readonly ActionContext _actionContext; - public TestResponseGenerator(IHttpContextAccessor httpContextAccessor) +#pragma warning disable ASPDEPR004 // Type or member is obsolete + public TestResponseGenerator(IActionContextAccessor contextAccessor) +#pragma warning restore ASPDEPR004 // Type or member is obsolete { - _httpContextAccessor = httpContextAccessor; - if (_httpContextAccessor.HttpContext == null) + _actionContext = contextAccessor.ActionContext; + if (_actionContext == null) { - throw new InvalidOperationException("HttpContext should not be null here."); + throw new InvalidOperationException("ActionContext should not be null here."); } } public ActionResult Generate(params string[] expectedUrls) { - var httpContext = _httpContextAccessor.HttpContext!; var link = (string)null; - var query = httpContext.Request.Query; + var query = _actionContext.HttpContext.Request.Query; if (query.ContainsKey("link")) { var values = query .Where(kvp => kvp.Key != "link" && kvp.Key != "link_action" && kvp.Key != "link_controller") .ToDictionary(kvp => kvp.Key.Substring("link_".Length), kvp => (object)kvp.Value[0]); - var urlHelper = GetUrlHelper(httpContext); + var urlHelper = GetUrlHelper(_actionContext); link = urlHelper.Action(query["link_action"], query["link_controller"], values); } - var endpoint = httpContext.GetEndpoint(); - var actionDescriptor = endpoint?.Metadata.GetMetadata(); - var attributeRoutingInfo = actionDescriptor?.AttributeRouteInfo; + var attributeRoutingInfo = _actionContext.ActionDescriptor.AttributeRouteInfo; return new OkObjectResult(new { expectedUrls = expectedUrls, - actualUrl = httpContext.Request.Path.Value, - routeName = attributeRoutingInfo?.Name, - routeValues = new Dictionary(httpContext.GetRouteData().Values), + actualUrl = _actionContext.HttpContext.Request.Path.Value, + routeName = attributeRoutingInfo == null ? null : attributeRoutingInfo.Name, + routeValues = new Dictionary(_actionContext.RouteData.Values), - action = actionDescriptor?.ActionName, - controller = actionDescriptor?.ControllerName, + action = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ActionName, + controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerName, link, }); } - private IUrlHelper GetUrlHelper(HttpContext httpContext) + private IUrlHelper GetUrlHelper(ActionContext context) { - var services = httpContext.RequestServices; - var urlHelperFactory = services.GetRequiredService(); - - // Create ActionContext from HttpContext for URL generation - var actionContext = new ActionContext( - httpContext, - httpContext.GetRouteData(), - httpContext.GetEndpoint()?.Metadata.GetMetadata() ?? new ControllerActionDescriptor()); - - var urlHelper = urlHelperFactory.GetUrlHelper(actionContext); + var services = context.HttpContext.RequestServices; + var urlHelper = services.GetRequiredService().GetUrlHelper(context); return urlHelper; } } diff --git a/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs b/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs index 1389499563e6..3a2a05a62c6f 100644 --- a/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs @@ -23,6 +23,9 @@ public void ConfigureServices(IServiceCollection services) services.AddLogging(); services.AddHttpContextAccessor(); services.AddScoped(); + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs b/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs index c0f41ce45af1..9ac2d3785f64 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs @@ -28,8 +28,10 @@ public void ConfigureServices(IServiceCollection services) ConfigureRoutingServices(services); - services.AddHttpContextAccessor(); services.AddScoped(); + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs index 10a607d09c54..b151cf138e00 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs @@ -17,8 +17,10 @@ public void ConfigureServices(IServiceCollection services) .AddNewtonsoftJson(); services.AddTransient(); - services.AddHttpContextAccessor(); services.AddScoped(); + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs index 883d71eb490a..7d7caf8378a7 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs @@ -32,8 +32,10 @@ public void ConfigureServices(IServiceCollection services) .AddNewtonsoftJson(); services.AddTransient(); - services.AddHttpContextAccessor(); services.AddScoped(); + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs index ae7813ff329c..3057ad832cc1 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs @@ -15,9 +15,11 @@ public void ConfigureServices(IServiceCollection services) // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); - services.AddHttpContextAccessor(); services.AddScoped(); // This is used by test response generator + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs index f1a16bab229f..9732a8a36bba 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs @@ -15,8 +15,10 @@ public void ConfigureServices(IServiceCollection services) .AddMvc() .AddNewtonsoftJson(); - services.AddHttpContextAccessor(); services.AddScoped(); + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs index 446084cfe353..0c1aa889ae8a 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs @@ -15,9 +15,11 @@ public void ConfigureServices(IServiceCollection services) // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); - services.AddHttpContextAccessor(); services.AddScoped(); // This is used by test response generator + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs index 48bf12784edd..04eac2138dae 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs @@ -30,8 +30,10 @@ public void ConfigureServices(IServiceCollection services) options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer); }); - services.AddHttpContextAccessor(); services.AddScoped(); + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs index 66dd08542575..b27e38b109b3 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs @@ -29,9 +29,11 @@ public void ConfigureServices(IServiceCollection services) ConfigureRoutingServices(services); - services.AddHttpContextAccessor(); services.AddScoped(); // This is used by test response generator + #pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete services.AddSingleton(); } diff --git a/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs b/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs index b8c6c33802a8..ebdb91d9fa3a 100644 --- a/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs @@ -13,8 +13,10 @@ public void ConfigureServices(IServiceCollection services) services.AddControllers(ConfigureMvcOptions) .AddNewtonsoftJson(); - services.AddHttpContextAccessor(); services.AddScoped(); +#pragma warning disable ASPDEPR004 // Type or member is obsolete + services.AddSingleton(); +#pragma warning restore ASPDEPR004 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) From f28767575bed835214a9aa9a8b78ed459c27a415 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 18 Jul 2025 20:44:23 +0000 Subject: [PATCH 7/7] Update obsolete attributes to use diagnostic ID ASPDEPR006 and updated message with URL Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com> --- .../src/Infrastructure/ActionContextAccessor.cs | 2 +- .../src/Infrastructure/ControllerActionInvoker.cs | 4 ++-- .../ControllerActionInvokerProvider.cs | 12 ++++++------ .../src/Infrastructure/IActionContextAccessor.cs | 2 +- .../Mvc.Core/src/Infrastructure/ResourceInvoker.cs | 8 ++++---- .../src/Routing/ControllerRequestDelegateFactory.cs | 12 ++++++------ .../Mvc.Core/test/Filters/MiddlewareFilterTest.cs | 4 ++-- .../Infrastructure/ControllerActionInvokerTest.cs | 8 ++++---- .../src/Infrastructure/PageActionInvoker.cs | 4 ++-- .../src/Infrastructure/PageActionInvokerProvider.cs | 12 ++++++------ .../src/Infrastructure/PageRequestDelegateFactory.cs | 12 ++++++------ .../test/Infrastructure/PageActionInvokerTest.cs | 4 ++-- src/Mvc/test/WebSites/BasicWebSite/Startup.cs | 4 ++-- .../BasicWebSite/StartupWithoutEndpointRouting.cs | 4 ++-- .../test/WebSites/Common/TestResponseGenerator.cs | 4 ++-- src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs | 4 ++-- src/Mvc/test/WebSites/RoutingWebSite/Startup.cs | 4 ++-- .../WebSites/RoutingWebSite/StartupForDynamic.cs | 4 ++-- .../RoutingWebSite/StartupForDynamicOrder.cs | 4 ++-- .../RoutingWebSite/StartupForEndpointFilters.cs | 4 ++-- .../WebSites/RoutingWebSite/StartupForFallback.cs | 4 ++-- .../test/WebSites/RoutingWebSite/StartupForGroups.cs | 4 ++-- .../RoutingWebSite/StartupForLinkGenerator.cs | 4 ++-- .../StartupRoutingDifferentBranches.cs | 4 ++-- src/Mvc/test/WebSites/VersioningWebSite/Startup.cs | 4 ++-- 25 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs index 3003544470d5..accf130e6bf0 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ActionContextAccessor.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Type that provides access to an . /// -[Obsolete("ActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version.", DiagnosticId = "ASPDEPR004")] +[Obsolete("ActionContextAccessor is obsolete and will be removed in a future version. For more information, visit https://aka.ms/aspnet/deprecate/006.", DiagnosticId = "ASPDEPR006")] public class ActionContextAccessor : IActionContextAccessor { internal static readonly IActionContextAccessor Null = new NullActionContextAccessor(); diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs index f3b46308cc98..436be14aeddc 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs @@ -30,9 +30,9 @@ internal partial class ControllerActionInvoker : ResourceInvoker, IActionInvoker internal ControllerActionInvoker( ILogger logger, DiagnosticListener diagnosticListener, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete IActionContextAccessor actionContextAccessor, -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete IActionResultTypeMapper mapper, ControllerContext controllerContext, ControllerActionInvokerCacheEntry cacheEntry, diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs index c65cdba1426b..4d70251c4340 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvokerProvider.cs @@ -23,9 +23,9 @@ internal sealed class ControllerActionInvokerProvider : IActionInvokerProvider private readonly ILogger _logger; private readonly DiagnosticListener _diagnosticListener; private readonly IActionResultTypeMapper _mapper; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete private readonly IActionContextAccessor _actionContextAccessor; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete public ControllerActionInvokerProvider( ControllerActionInvokerCache controllerActionInvokerCache, @@ -43,9 +43,9 @@ public ControllerActionInvokerProvider( ILoggerFactory loggerFactory, DiagnosticListener diagnosticListener, IActionResultTypeMapper mapper, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete IActionContextAccessor? actionContextAccessor) -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete { _controllerActionInvokerCache = controllerActionInvokerCache; _valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray(); @@ -55,9 +55,9 @@ public ControllerActionInvokerProvider( _logger = loggerFactory.CreateLogger(typeof(ControllerActionInvoker)); _diagnosticListener = diagnosticListener; _mapper = mapper; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public int Order => -1000; diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs index 0609f62acdb9..60fa2bdf4931 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/IActionContextAccessor.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure; /// /// Defines an interface for exposing an . /// -[Obsolete("IActionContextAccessor is obsolete. Use IHttpContextAccessor instead and access the endpoint information from HttpContext.GetEndpoint(). This type will be removed in a future version.", DiagnosticId = "ASPDEPR004")] +[Obsolete("IActionContextAccessor is obsolete and will be removed in a future version. For more information, visit https://aka.ms/aspnet/deprecate/006.", DiagnosticId = "ASPDEPR006")] public interface IActionContextAccessor { /// diff --git a/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs b/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs index 2edeb89ee583..6d2422bea797 100644 --- a/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs +++ b/src/Mvc/Mvc.Core/src/Infrastructure/ResourceInvoker.cs @@ -15,9 +15,9 @@ internal abstract partial class ResourceInvoker { protected readonly DiagnosticListener _diagnosticListener; protected readonly ILogger _logger; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete protected readonly IActionContextAccessor _actionContextAccessor; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete protected readonly IActionResultTypeMapper _mapper; protected readonly ActionContext _actionContext; protected readonly IFilterMetadata[] _filters; @@ -39,9 +39,9 @@ internal abstract partial class ResourceInvoker public ResourceInvoker( DiagnosticListener diagnosticListener, ILogger logger, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete IActionContextAccessor actionContextAccessor, -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete IActionResultTypeMapper mapper, ActionContext actionContext, IFilterMetadata[] filters, diff --git a/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs b/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs index 5f19dd091b38..4b4bbd1313c9 100644 --- a/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs +++ b/src/Mvc/Mvc.Core/src/Routing/ControllerRequestDelegateFactory.cs @@ -24,9 +24,9 @@ internal sealed class ControllerRequestDelegateFactory : IRequestDelegateFactory private readonly ILogger _logger; private readonly DiagnosticListener _diagnosticListener; private readonly IActionResultTypeMapper _mapper; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete private readonly IActionContextAccessor _actionContextAccessor; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete private readonly bool _enableActionInvokers; public ControllerRequestDelegateFactory( @@ -45,9 +45,9 @@ public ControllerRequestDelegateFactory( ILoggerFactory loggerFactory, DiagnosticListener diagnosticListener, IActionResultTypeMapper mapper, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete IActionContextAccessor? actionContextAccessor) -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete { _controllerActionInvokerCache = controllerActionInvokerCache; _valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray(); @@ -58,9 +58,9 @@ public ControllerRequestDelegateFactory( _logger = loggerFactory.CreateLogger(); _diagnosticListener = diagnosticListener; _mapper = mapper; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public RequestDelegate? CreateRequestDelegate(ActionDescriptor actionDescriptor, RouteValueDictionary? dataTokens) diff --git a/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs b/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs index 596befca5274..14a605a53667 100644 --- a/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs +++ b/src/Mvc/Mvc.Core/test/Filters/MiddlewareFilterTest.cs @@ -398,9 +398,9 @@ public TestControllerActionInvoker( : base( logger, diagnosticListener, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete ActionContextAccessor.Null, -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete mapper, CreateControllerContext(actionContext, valueProviderFactories, maxAllowedErrorsInModelState), CreateCacheEntry((ControllerActionDescriptor)actionContext.ActionDescriptor, controllerFactory), diff --git a/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs b/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs index 67099d6740ec..69bdac9ed518 100644 --- a/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs +++ b/src/Mvc/Mvc.Core/test/Infrastructure/ControllerActionInvokerTest.cs @@ -1432,9 +1432,9 @@ public async Task Invoke_UsesDefaultValuesIfNotBound() var invoker = new ControllerActionInvoker( new NullLoggerFactory().CreateLogger(), new DiagnosticListener("Microsoft.AspNetCore"), -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete ActionContextAccessor.Null, -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete new ActionResultTypeMapper(), controllerContext, cacheEntry, @@ -1771,9 +1771,9 @@ private ControllerActionInvoker CreateInvoker( var invoker = new ControllerActionInvoker( logger, diagnosticSource, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete ActionContextAccessor.Null, -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete new ActionResultTypeMapper(), controllerContext, cacheEntry, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs index f2f36c7007f1..161bf9800b58 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvoker.cs @@ -35,9 +35,9 @@ public PageActionInvoker( IPageHandlerMethodSelector handlerMethodSelector, DiagnosticListener diagnosticListener, ILogger logger, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete IActionContextAccessor actionContextAccessor, -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete IActionResultTypeMapper mapper, PageContext pageContext, IFilterMetadata[] filterMetadata, diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs index 27658149617b..3b9781cd6751 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageActionInvokerProvider.cs @@ -25,9 +25,9 @@ internal sealed class PageActionInvokerProvider : IActionInvokerProvider private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _logger; private readonly IActionResultTypeMapper _mapper; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete private readonly IActionContextAccessor _actionContextAccessor; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete public PageActionInvokerProvider( PageLoader pageLoader, @@ -40,9 +40,9 @@ public PageActionInvokerProvider( DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory, IActionResultTypeMapper mapper, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete IActionContextAccessor? actionContextAccessor = null) -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete { _pageLoader = pageLoader; _pageActionInvokerCache = pageActionInvokerCache; @@ -54,9 +54,9 @@ public PageActionInvokerProvider( _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _mapper = mapper; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } // For testing diff --git a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs index d5f6ff007918..404e5dd37739 100644 --- a/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs +++ b/src/Mvc/Mvc.RazorPages/src/Infrastructure/PageRequestDelegateFactory.cs @@ -26,9 +26,9 @@ internal sealed class PageRequestDelegateFactory : IRequestDelegateFactory private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _logger; private readonly IActionResultTypeMapper _mapper; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete private readonly IActionContextAccessor _actionContextAccessor; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete private readonly bool _enableActionInvokers; public PageRequestDelegateFactory( @@ -55,9 +55,9 @@ public PageRequestDelegateFactory( DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory, IActionResultTypeMapper mapper, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete IActionContextAccessor? actionContextAccessor) -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete { _cache = cache; _valueProviderFactories = mvcOptions.Value.ValueProviderFactories.ToArray(); @@ -69,9 +69,9 @@ public PageRequestDelegateFactory( _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _mapper = mapper; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public RequestDelegate? CreateRequestDelegate(ActionDescriptor actionDescriptor, RouteValueDictionary? dataTokens) diff --git a/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs b/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs index 6a64e7993aac..2294563bc156 100644 --- a/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs +++ b/src/Mvc/Mvc.RazorPages/test/Infrastructure/PageActionInvokerTest.cs @@ -1565,9 +1565,9 @@ object pageFactory(PageContext context, ViewContext viewContext) selector.Object, diagnosticListener ?? new DiagnosticListener("Microsoft.AspNetCore"), logger ?? NullLogger.Instance, -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete ActionContextAccessor.Null, -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete new ActionResultTypeMapper(), pageContext, filters ?? Array.Empty(), diff --git a/src/Mvc/test/WebSites/BasicWebSite/Startup.cs b/src/Mvc/test/WebSites/BasicWebSite/Startup.cs index df7f17b1b356..af44ae54e992 100644 --- a/src/Mvc/test/WebSites/BasicWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/BasicWebSite/Startup.cs @@ -20,9 +20,9 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor(); services.AddScoped(); services.AddScoped(); - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs b/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs index b9f319db2fc9..a43f14b6dfc2 100644 --- a/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs +++ b/src/Mvc/test/WebSites/BasicWebSite/StartupWithoutEndpointRouting.cs @@ -49,9 +49,9 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddTransient(); services.AddScoped(); - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete services.TryAddSingleton(CreateWeatherForecastService); } diff --git a/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs b/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs index d254fbf46474..ab7a804920eb 100644 --- a/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs +++ b/src/Mvc/test/WebSites/Common/TestResponseGenerator.cs @@ -12,9 +12,9 @@ public class TestResponseGenerator { private readonly ActionContext _actionContext; -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete public TestResponseGenerator(IActionContextAccessor contextAccessor) -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete { _actionContext = contextAccessor.ActionContext; if (_actionContext == null) diff --git a/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs b/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs index 3a2a05a62c6f..07e999ccde7a 100644 --- a/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/GenericHostWebSite/Startup.cs @@ -23,9 +23,9 @@ public void ConfigureServices(IServiceCollection services) services.AddLogging(); services.AddHttpContextAccessor(); services.AddScoped(); - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs b/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs index 9ac2d3785f64..c3ef0149527d 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/Startup.cs @@ -29,9 +29,9 @@ public void ConfigureServices(IServiceCollection services) ConfigureRoutingServices(services); services.AddScoped(); - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs index b151cf138e00..9726929e10e2 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs @@ -18,9 +18,9 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient(); services.AddScoped(); - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs index 7d7caf8378a7..08b61b0c0ea6 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamicOrder.cs @@ -33,9 +33,9 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient(); services.AddScoped(); - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs index 3057ad832cc1..f8424d5c41f3 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForEndpointFilters.cs @@ -17,9 +17,9 @@ public void ConfigureServices(IServiceCollection services) services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); services.AddScoped(); // This is used by test response generator - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs index 9732a8a36bba..732ec4b82a61 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForFallback.cs @@ -16,9 +16,9 @@ public void ConfigureServices(IServiceCollection services) .AddNewtonsoftJson(); services.AddScoped(); - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete // Used by some controllers defined in this project. services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs index 0c1aa889ae8a..c055dc3ff23a 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForGroups.cs @@ -17,9 +17,9 @@ public void ConfigureServices(IServiceCollection services) services.Configure(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); services.AddScoped(); // This is used by test response generator - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs index 04eac2138dae..2792eb795dfe 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupForLinkGenerator.cs @@ -31,9 +31,9 @@ public void ConfigureServices(IServiceCollection services) }); services.AddScoped(); - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public void Configure(IApplicationBuilder app) diff --git a/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs b/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs index b27e38b109b3..371540eee06d 100644 --- a/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs +++ b/src/Mvc/test/WebSites/RoutingWebSite/StartupRoutingDifferentBranches.cs @@ -31,9 +31,9 @@ public void ConfigureServices(IServiceCollection services) services.AddScoped(); // This is used by test response generator - #pragma warning disable ASPDEPR004 // Type or member is obsolete + #pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete services.AddSingleton(); } diff --git a/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs b/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs index ebdb91d9fa3a..71e417b8bb98 100644 --- a/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/VersioningWebSite/Startup.cs @@ -14,9 +14,9 @@ public void ConfigureServices(IServiceCollection services) .AddNewtonsoftJson(); services.AddScoped(); -#pragma warning disable ASPDEPR004 // Type or member is obsolete +#pragma warning disable ASPDEPR006 // Type or member is obsolete services.AddSingleton(); -#pragma warning restore ASPDEPR004 // Type or member is obsolete +#pragma warning restore ASPDEPR006 // Type or member is obsolete } public virtual void Configure(IApplicationBuilder app)