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
<PackageReference Include="Demarbit.Results.AspNetCore" Version="1.0.0" />
<PackageVersion Include="Demarbit.Results.AspNetCore" Version="1.0.0" />
<PackageReference Include="Demarbit.Results.AspNetCore" />
paket add Demarbit.Results.AspNetCore --version 1.0.0
#r "nuget: Demarbit.Results.AspNetCore, 1.0.0"
#:package Demarbit.Results.AspNetCore@1.0.0
#addin nuget:?package=Demarbit.Results.AspNetCore&version=1.0.0
#tool nuget:?package=Demarbit.Results.AspNetCore&version=1.0.0
Demarbit.Results
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 | 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
- Demarbit.Results (>= 1.0.0)
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 |