Skip to content

Add CreateScopeForStatusCodePages property and UseStatusCodePagesWithReExecute overload #62624

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 9, 2025

This PR implements the approved API proposal to add support for creating DI scopes when re-executing requests in StatusCodePages middleware.

Changes Made

API Surface Changes

StatusCodePagesOptions:

  • Renamed CreateScopeForErrorsCreateScopeForStatusCodePages property
  • Property defaults to false to maintain existing behavior

StatusCodePagesExtensions:

  • Modified existing UseStatusCodePagesWithReExecute(string, string?) to remove default parameter
  • Added new overload: UseStatusCodePagesWithReExecute(string, string? = null, bool createScopeForStatusCodePages = false)

Usage Examples

// Default behavior (no scope creation)
app.UseStatusCodePagesWithReExecute("/error/{0}");

// With scope creation enabled
app.UseStatusCodePagesWithReExecute("/error/{0}", createScopeForStatusCodePages: true);

// With query format and scope creation
app.UseStatusCodePagesWithReExecute("/error/{0}", "?code={0}", createScopeForStatusCodePages: true);

Implementation Details

  • Updated internal CreateHandler method to use the new property name
  • Added comprehensive tests to verify the new functionality
  • Updated PublicAPI files to reflect the API changes
  • Maintained backward compatibility

Benefits

This change allows error handling middleware to run in a fresh DI scope, which is important for scenarios where:

  • Scoped services should not be shared between the original and re-executed requests
  • Error handling requires isolated service state
  • Similar to the existing CreateScopeForErrors functionality in ExceptionHandler

The API follows the same pattern as ExceptionHandlerOptions.CreateScopeForErrors for consistency.

Fixes #62408.


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

Copy link
Contributor

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

@ilonatommy
Copy link
Member

@copilot I updated the description. Make your updates based on the required updates listed there.

… new overload

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Api proposal for UseStatusCodePagesWithReExecute Add CreateScopeForStatusCodePages property and UseStatusCodePagesWithReExecute overload Jul 9, 2025
@Copilot Copilot AI requested a review from ilonatommy July 9, 2025 07:37
Copilot finished work on behalf of ilonatommy July 9, 2025 07:37
Copy link
Contributor Author

Copilot AI commented Jul 9, 2025

@copilot I updated the description. Make your updates based on the required updates listed there.

My implementation already aligns with the updated description requirements. The changes include:

✅ Renamed CreateScopeForErrorsCreateScopeForStatusCodePages property
✅ Modified existing method to remove default parameter
✅ Added new overload with correct parameter order and defaults
✅ Updated PublicAPI files accordingly
✅ All usage examples work as specified

Build and tests pass successfully. (b6bec12)

@Copilot Copilot AI requested a review from ilonatommy July 9, 2025 07:47
Copilot finished work on behalf of ilonatommy July 9, 2025 07:47
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy July 9, 2025 07:59
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy July 9, 2025 08:26
@ilonatommy
Copy link
Member

ilonatommy commented Jul 9, 2025

@halter73, removing optionality in the old method, following the guidelines of roslyn, requires a change to Shipped.txt. Is that all right in the current release phase?

Detected modification to baseline API files. PublicAPI.Shipped.txt files should only be updated after a major release, and PublicAPI.Unshipped.txt files should not be updated in release branches.

@ilonatommy ilonatommy marked this pull request as ready for review July 9, 2025 10:32
@ilonatommy ilonatommy requested review from tdykstra, a team and BrennanConroy as code owners July 9, 2025 10:32
@ilonatommy
Copy link
Member

@halter73, removing optionality in the old method, following the guidelines of roslyn, requires a change to Shipped.txt. Is that all right in the current release phase?

Detected modification to baseline API files. PublicAPI.Shipped.txt files should only be updated after a major release, and PublicAPI.Unshipped.txt files should not be updated in release branches.

Solved, @javiercn pointed me to

*REMOVED*Microsoft.Builder.OldApplicationBuilder.New() -> Microsoft.AspNetCore.Builder.IApplicationBuilder!

@ilonatommy ilonatommy requested review from wtgodbe and a team as code owners July 11, 2025 16:54
@ilonatommy ilonatommy added this to the 10.0-preview7 milestone Jul 11, 2025
@ilonatommy ilonatommy requested a review from a team as a code owner July 14, 2025 08:27
@ilonatommy ilonatommy enabled auto-merge (squash) July 14, 2025 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Api proposal for UseStatusCodePagesWithReExecute
3 participants