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

Create IResult-returning static methods #33729

Closed
halter73 opened this issue Jun 21, 2021 · 2 comments · Fixed by #33843
Closed

Create IResult-returning static methods #33729

halter73 opened this issue Jun 21, 2021 · 2 comments · Fixed by #33843
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing
Milestone

Comments

@halter73
Copy link
Member

halter73 commented Jun 21, 2021

IResult-returning static methods would allow something like using static Microsoft.AspNetCore.Http.Results and makes for better return type inference for IResult-returning lambdas, so you don't have to do casting like the following you have to do using constructors today.

app.MapGet("/todos/{id}", async (int id) =>
{
    using var db = new TodoDbContext(options);
 
    if (await db.Todos.FindAsync(id) is not Todo todo)
    {
        return (IResult)new NotFoundResult();
    }
 
    return new JsonResult(todo);
})

With, IResult returning NotFound and Ok methods the (IResult) casting can be removed.

app.MapGet("/todos/{id}", async (int id) =>
{
    using var db = new TodoDbContext(options);
 
    if (await db.Todos.FindAsync(id) is not Todo todo)
    {
        return NotFound();
    }
 
    return Json(todo);
})
@davidfowl
Copy link
Member

We should start with these methods and remove a bunch:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase?view=aspnetcore-5.0

cc @pranavkm

@javiercn javiercn added feature-minimal-actions Controller-like actions for endpoint routing area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Jun 22, 2021
@pranavkm pranavkm added area-runtime and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Jun 22, 2021
@BrennanConroy BrennanConroy added this to the 6.0-preview7 milestone Jun 23, 2021
pranavkm added a commit that referenced this issue Jun 30, 2021
* Separate IResult based results from ActionResults

Fixes #33729
@davidfowl
Copy link
Member

@pranavkm StatusCodeResult still implements IResult. Is that intentional?

@ghost ghost locked as resolved and limited conversation to collaborators Aug 4, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants