Desfecho.AspNetCore 2.1.0

dotnet add package Desfecho.AspNetCore --version 2.1.0
                    
NuGet\Install-Package Desfecho.AspNetCore -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Desfecho.AspNetCore" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Desfecho.AspNetCore" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Desfecho.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Desfecho.AspNetCore --version 2.1.0
                    
#r "nuget: Desfecho.AspNetCore, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Desfecho.AspNetCore@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Desfecho.AspNetCore&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Desfecho.AspNetCore&version=2.1.0
                    
Install as a Cake Tool

Desfecho

CI CD NuGet NuGet License

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 Result.NotFound($"Todo item '{id}' was not found.");
    }

    todoItem.Complete();
    return todoItem;
}

public Result DeleteTodoItem(Guid id)
{
    return _todoItems.Remove(id)
        ? Result.Success()
        : Result.NotFound($"Todo item '{id}' was not found.");
}

Result<TValue> converts implicitly from TValue, Error and ErrorList, so returning one is all you need, no wrapping, no new. Result is the same without a value.

Consuming

var message = result.Match(
    todoItem => $"Completed '{todoItem.Title}'.",
    errors => errors[0].Description);

if (result.TryGetValue(out var todoItem)) { ... }

var dto = result
    .Then(todoItem => todoItem.Archive())      // returns Result<T> or Result
    .Map(todoItem => new TodoItemDto(todoItem));

Map also works on Task and ValueTask of a Result<TValue>, so a handler call can be mapped and converted in one expression:

sender.Send(command, ct).Map(SignInResponse.From).ToOk();

Value, Error and Errors throw if the result is the other case; prefer Match or TryGetValue / TryGetErrors.

Errors

An Error is a Type, a Description, and an optional Property (set for validation errors):

Result.Invalid("Title", "Title is required.");      // ErrorType.Validation
Result.Unauthorized("Authentication is required."); // ErrorType.Unauthorized
Result.Forbidden("You do not have access.");        // ErrorType.Forbidden
Result.NotFound("Todo item was not found.");        // ErrorType.NotFound
Result.Conflict("Todo item already exists.");       // ErrorType.Conflict
Result.Failure("Something went wrong.");            // ErrorType.Failure

An ErrorList holds several errors. Result.Invalid also takes an existing property-to-messages map, e.g. from FluentValidation:

var validation = await validator.ValidateAsync(request, ct);

if (!validation.IsValid)
{
    return Result.Invalid(validation.ToDictionary());
}

result.Error is the first error, result.Errors all of them.

ASP.NET Core

Desfecho.AspNetCore turns a Result into a minimal API IResult, mapping errors to ProblemDetails (Validation → 400, Unauthorized → 401, Forbidden → 403, NotFound → 404, Conflict → 409, Failure → 500). When all errors are Validation, the response is a validation problem grouped by Property; otherwise it describes the first error..

app.MapPost("/todo-items", (CreateTodoItemRequest request, ISender sender, CancellationToken ct) =>
    sender.Send(new CreateTodoItemCommand(request.TodoListId, request.Title), ct)
        .ToCreated(value => $"/todo-items/{value.Id}"));

ToOk(), ToCreated(location) and ToNoContent() work on Result/Result<TValue> and on Task of them; ToProblem() on an Error or Errors is available directly for anything else.

Packages

Package Contents
Desfecho Result, Result<TValue>, Error, ErrorList, 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 322 10/6/2026
2.0.0 109 10/6/2026
1.2.0 100 10/6/2026
1.1.0 183 9/7/2026
1.0.0 113 8/31/2026