Desfecho.AspNetCore
1.2.0
See the version list below for details.
dotnet add package Desfecho.AspNetCore --version 1.2.0
NuGet\Install-Package Desfecho.AspNetCore -Version 1.2.0
<PackageReference Include="Desfecho.AspNetCore" Version="1.2.0" />
<PackageVersion Include="Desfecho.AspNetCore" Version="1.2.0" />
<PackageReference Include="Desfecho.AspNetCore" />
paket add Desfecho.AspNetCore --version 1.2.0
#r "nuget: Desfecho.AspNetCore, 1.2.0"
#:package Desfecho.AspNetCore@1.2.0
#addin nuget:?package=Desfecho.AspNetCore&version=1.2.0
#tool nuget:?package=Desfecho.AspNetCore&version=1.2.0
Desfecho
A simple and lightweight Result pattern implementation for .NET.
dotnet add package Desfecho
dotnet add package Desfecho.AspNetCore
Tech stack
.NET 10 · xUnit v3 · Shouldly
Why
Stop throwing exceptions for expected failures. Return a Result<TValue> instead: it's either a value or one or more Errors.
public Result<TodoItem> CompleteTodoItem(Guid id)
{
var todoItem = _todoItems.Find(id);
if (todoItem is null)
{
return Error.NotFound("TodoItem.NotFound", $"Todo item '{id}' was not found.");
}
todoItem.Complete();
return todoItem;
}
var result = CompleteTodoItem(id);
var message = result.Match(
todoItem => $"Completed '{todoItem.Title}'.",
errors => errors[0].Description);
Result<TValue> converts implicitly from TValue, Error and List<Error>, so returning one is all you need, no wrapping, no new.
Errors
An Error is a Code, a Description, and a Type:
Error.Validation("TodoItem.Title", "Title is required.");
Error.Unauthorized("TodoItem.Unauthorized", "Authentication is required.");
Error.Forbidden("TodoItem.Forbidden", "You do not have access to this todo item.");
Error.NotFound("TodoItem.NotFound", "Todo item was not found.");
Error.Conflict("TodoItem.Conflict", "Todo item already exists.");
Type is one of Validation, Unauthorized, Forbidden, NotFound or Conflict, used by Desfecho.AspNetCore to pick an HTTP status code.
ASP.NET Core
Desfecho.AspNetCore turns a Result<TValue> into a minimal API IResult, mapping errors to ProblemDetails (Validation → 400, Unauthorized → 401, Forbidden → 403, NotFound → 404, Conflict → 409).
app.MapPost("/todo-items", async (CreateTodoItemRequest request, ISender sender, CancellationToken ct) =>
{
var result = await sender.Send(new CreateTodoItemCommand(request.TodoListId, request.Title), ct);
return result.ToCreated(value => $"/todo-items/{value.Id}");
});
ToOk(), ToCreated(location), ToAccepted() and ToNoContent() cover the common cases; errors.ToProblem() is available directly for anything else.
Packages
| Package | Contents |
|---|---|
Desfecho |
Result<TValue>, Error, ErrorType |
Desfecho.AspNetCore |
Result<TValue> → minimal API IResult |
Development
dotnet restore
dotnet build --configuration Release
dotnet test --configuration Release
dotnet format --verify-no-changes --severity info
Deployment
Versioning, changelog, and NuGet publish are automated by release-please, tracking Desfecho and Desfecho.AspNetCore as independent packages: merges to main update a release PR from Conventional Commits, and merging that PR tags the release and publishes the affected package(s) to NuGet via GitHub Actions.
License
Licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Desfecho (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.