Closed
Description
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);
})