AKlaus / DomainResult

Tiny package for decoupling domain operation results from IActionResult and IResult types of ASP.NET Web API
Apache License 2.0
53 stars 3 forks source link

DomainResult.Mvc: Add extension to convert IDomainResult to IResult #43

Closed AKlaus closed 1 year ago

AKlaus commented 2 years ago

Currently, DomainResult.Mvc package converts IDomainResult and IDomainResult<T> to IActionResult and ActionResult<T>.

.NET 6 added IResult for producing common HTTP responses (see announcement).

Hence, DomainResult.Mvc package has to provide extensions to convert

NOTE: IResult is independent from IActionResult and is meant to be used in the minimal APIs:

app.MapPut("/todos/{id}", async (TodoDbContext db, int id, Todo todo) =>
{
    if (id != todo.Id)
        return Results.BadRequest();

    if (!await db.Todos.AnyAsync(x => x.Id == id))
        return Results.NotFound();

    db.Update(todo);
    await db.SaveChangesAsync();

    return Results.Ok();
});