The Wayback Machine - https://web.archive.org/web/20220212034113/https://github.com/dotnet/aspnetcore/issues/40168
Skip to content
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

Add Results.Empty #40168

Open
davidfowl opened this issue Feb 12, 2022 · 1 comment
Open

Add Results.Empty #40168

davidfowl opened this issue Feb 12, 2022 · 1 comment

Comments

@davidfowl
Copy link
Member

@davidfowl davidfowl commented Feb 12, 2022

Background and Motivation

Sometimes you want to return a result that does not mutate the response in anyway. This happens when you have multiple branches in a route handle and one of them should be a noop. You are forced to return an IResult and we don't have a built in result type that fills this role. Mvc has EmptyResult for this purpose.

Proposed API

namespace Microsoft.AspNetCore.Http
{
    public static class Results
    {
        public static IResult Empty(); // This could also be a property
    }
}

Usage Examples

app.MapGet("/{id}", (HttpContext context, string id) =>
{
    var httpProcessor = GetTargetStream(id);
    if (httpProcessor is null) return Results.NotFound();
 
    await httpProcessor.ProcessAsync(context);
     // Don't change what the httpProcessor did
    return Results.Empty();
});

Alternative Designs

Force people to write their own.

Risks

None

@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Feb 12, 2022

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant