Demarbit.Results.AspNetCore 1.0.0

dotnet add package Demarbit.Results.AspNetCore --version 1.0.0
                    
NuGet\Install-Package Demarbit.Results.AspNetCore -Version 1.0.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="Demarbit.Results.AspNetCore" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Demarbit.Results.AspNetCore" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Demarbit.Results.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 Demarbit.Results.AspNetCore --version 1.0.0
                    
#r "nuget: Demarbit.Results.AspNetCore, 1.0.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 Demarbit.Results.AspNetCore@1.0.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=Demarbit.Results.AspNetCore&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Demarbit.Results.AspNetCore&version=1.0.0
                    
Install as a Cake Tool

Demarbit.Results

CI-CD Quality Gate Status NuGet

A lightweight Result pattern library for .NET 10. Replace exceptions as control flow with explicit Result<TValue> and Result<TValue, TError> types — designed for CQRS pipelines and Clean Architecture.

Getting Started

dotnet add package Demarbit.Results

For ASP.NET Core integration (ProblemDetails mapping, minimal API support):

dotnet add package Demarbit.Results.AspNetCore

Return Results from handlers

using Demarbit.Results;

// Implicit conversions make this ergonomic
public Result<Order> Handle(CreateOrderCommand command)
{
    if (string.IsNullOrEmpty(command.Name))
        return new ValidationError("Name", "Name is required");

    var order = Order.Create(command.Name);
    return order; // implicitly wraps in Result<Order>
}

Pattern match on results

var result = handler.Handle(command);

var response = result.Match(
    onSuccess: order => $"Created order {order.Id}",
    onFailure: error => $"Failed: {error.Message}");

Chain operations with combinators

var output = await GetOrderAsync(id)
    .Map(order => order.ToDto())
    .TapAsync(dto => LogAccessAsync(dto.Id))
    .Match(
        onSuccess: dto => Results.Ok(dto),
        onFailure: error => Results.Problem(error.ToProblemDetails()));

Validate with multiple errors

return Result.Validate(
    order,
    Error.When(string.IsNullOrEmpty(order.Name), "Name", "Name is required"),
    Error.When(order.Quantity <= 0, "Quantity", "Must be positive"),
    Error.When(order.Total < 0, "Total", "Cannot be negative"));

Map to HTTP responses (ASP.NET Core)

using Demarbit.Results.AspNetCore;

// In a minimal API endpoint
app.MapPost("/orders", (CreateOrderCommand cmd, IOrderService svc) =>
    svc.CreateOrder(cmd).ToHttpResult());
// Success → 200 OK, ValidationError → 400, NotFoundError → 404, ConflictError → 409

// Or use the endpoint filter for automatic mapping
app.MapGroup("/api")
   .WithResultMapping();

Error Types

Error Type Code HTTP Status
ValidationError VALIDATION_FAILED 400 Bad Request
UnauthorizedError UNAUTHORIZED 401 Unauthorized
ForbiddenError FORBIDDEN 403 Forbidden
NotFoundError NOT_FOUND 404 Not Found
ConflictError CONFLICT 409 Conflict
Custom Error Your code 422 Unprocessable Entity

Packages

Package Description
Demarbit.Results Core Result types, error types, and combinators. Zero dependencies.
Demarbit.Results.AspNetCore ToHttpResult(), ProblemDetails mapping, endpoint filter.

Dual-Generic Results

For domain methods that return specific error types, use Result<TValue, TError> to enable exhaustive switch matching:

public Result<Order, OrderError> PlaceOrder(OrderRequest request)
{
    if (!request.IsValid)
        return new OrderValidationError(request.Errors);

    if (inventory.IsOutOfStock(request.ProductId))
        return new OutOfStockError(request.ProductId);

    return Order.Create(request);
}

// Callers get typed errors for exhaustive matching
var message = result.Match(
    onSuccess: order => "Placed!",
    onFailure: error => error switch
    {
        OrderValidationError ve => $"Invalid: {ve.Message}",
        OutOfStockError oos => $"Out of stock: {oos.ProductId}",
        _ => "Unknown error"
    });

Convert to single-generic when crossing into the application layer:

Result<Order> applicationResult = domainResult.ToResult();

License

MIT — see LICENSE for details.

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
1.0.0 76 2/20/2026