Repository: dotnet/aspnetcore
File: src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesExtensions.cs (C#)

Code before:
    /// </summary>
    /// <param name="app"></param>
    /// <param name="configuration"></param>
    /// <returns></returns>
    public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Action<IApplicationBuilder> configuration)
    {
        ArgumentNullException.ThrowIfNull(app);

        var builder = app.New();
        configuration(builder);
        var tangent = builder.Build();
        return app.UseStatusCodePages(context => tangent(context.HttpContext));
    }

    /// <summary>
    /// Adds a StatusCodePages middleware to the pipeline. Specifies that the response body should be generated by
    /// re-executing the request pipeline using an alternate path. This path may contain a '{0}' placeholder of the status code.
    /// </summary>
    /// <param name="app"></param>
    /// <param name="pathFormat"></param>
    /// <param name="queryFormat"></param>
    /// <returns></returns>
    public static IApplicationBuilder UseStatusCodePagesWithReExecute(
        this IApplicationBuilder app,
        string pathFormat,
        string? queryFormat)
    {
        ArgumentNullException.ThrowIfNull(app);

        // Only use this path if there's a global router (in the 'WebApplication' case).
        if (app.Properties.TryGetValue(RerouteHelper.GlobalRouteBuilderKey, out var routeBuilder) && routeBuilder is not null)
        {
            return app.Use(next =>
            {
                var newNext = RerouteHelper.Reroute(app, routeBuilder, next);
                return new StatusCodePagesMiddleware(next,
                    Options.Create(new StatusCodePagesOptions() { HandleAsync = CreateHandler(pathFormat, queryFormat, newNext) })).Invoke;
            });
        }

        return app.UseStatusCodePages(CreateHandler(pathFormat, queryFormat));
    }

    /// <summary>
    /// Adds a StatusCodePages middleware to the pipeline. Specifies that the response body should be generated by
    /// re-executing the request pipeline using an alternate path. This path may contain a '{0}' placeholder of the status code.
    /// </summary>
    /// <param name="app"></param>
    /// <param name="pathFormat"></param>
    /// <param name="queryFormat"></param>
    /// <param name="createScopeForStatusCodePages"></param>

Review comment (suggestion):
Remove nullability of this parameter. Both here and in the Shipped txt. Add a comment at the top of the method:
```
// 1.0 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
```

Code after:
    /// </summary>
    /// <param name="app"></param>
    /// <param name="configuration"></param>
    /// <returns></returns>
    public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder app, Action<IApplicationBuilder> configuration)
    {
        ArgumentNullException.ThrowIfNull(app);

        var builder = app.New();
        configuration(builder);
        var tangent = builder.Build();
        return app.UseStatusCodePages(context => tangent(context.HttpContext));
    }

    /// <summary>
    /// Adds a StatusCodePages middleware to the pipeline. Specifies that the response body should be generated by
    /// re-executing the request pipeline using an alternate path. This path may contain a '{0}' placeholder of the status code.
    /// </summary>
    /// <param name="app"></param>
    /// <param name="pathFormat"></param>
    /// <param name="queryFormat"></param>
    /// <returns></returns>
    public static IApplicationBuilder UseStatusCodePagesWithReExecute(
        this IApplicationBuilder app,
        string pathFormat,
        string queryFormat)
    {
        ArgumentNullException.ThrowIfNull(app);

        // Only use this path if there's a global router (in the 'WebApplication' case).
        if (app.Properties.TryGetValue(RerouteHelper.GlobalRouteBuilderKey, out var routeBuilder) && routeBuilder is not null)
        {
            return app.Use(next =>
            {
                var newNext = RerouteHelper.Reroute(app, routeBuilder, next);
                return new StatusCodePagesMiddleware(next,
                    Options.Create(new StatusCodePagesOptions() { HandleAsync = CreateHandler(pathFormat, queryFormat, newNext) })).Invoke;
            });
        }

        return app.UseStatusCodePages(CreateHandler(pathFormat, queryFormat));
    }

    /// <summary>
    /// Adds a StatusCodePages middleware to the pipeline. Specifies that the response body should be generated by
    /// re-executing the request pipeline using an alternate path. This path may contain a '{0}' placeholder of the status code.
    /// </summary>
    /// <param name="app"></param>
    /// <param name="pathFormat"></param>
    /// <param name="queryFormat"></param>
    /// <param name="createScopeForStatusCodePages">Whether or not to create a new <see cref="IServiceProvider"/> scope.</param>