CoreMesh.Result
0.3.1
dotnet add package CoreMesh.Result --version 0.3.1
NuGet\Install-Package CoreMesh.Result -Version 0.3.1
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="CoreMesh.Result" Version="0.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreMesh.Result" Version="0.3.1" />
<PackageReference Include="CoreMesh.Result" />
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 CoreMesh.Result --version 0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CoreMesh.Result, 0.3.1"
#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 CoreMesh.Result@0.3.1
#: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=CoreMesh.Result&version=0.3.1
#tool nuget:?package=CoreMesh.Result&version=0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
繁體中文 | English
CoreMesh.Result
CoreMesh.Result provides a strongly-typed result pattern for ASP.NET Core applications, with built-in HTTP response mapping via Minimal API TypedResults.
It allows you to:
- Return operation outcomes as
Result/Result<T>from service or domain layers - Carry HTTP semantics (
Ok,NotFound,Invalid, etc.) without depending on ASP.NET Core in your business logic - Convert results to
IResultat the API boundary with a single call
Features
Result/Result<T>: non-generic and generic result typesError: machine-readable code + human-readable descriptionResultStatus: enum encoding the HTTP outcome (Ok,Created,NotFound,Forbidden,Invalid,BadRequest,NoContent)ResultExtensions: static factory methods (Result.Ok(),Result<T>.NotFound(error), etc.)HttpResultExtensions: converts results toIResultfor Minimal API endpointsApiResponse/ApiResponse<T>: unified JSON response envelopeToFile(): binary and stream file responsesToServerSentEvents(): SSE streaming responsesToSignIn()/ToSignOut(): ASP.NET Core authentication responses
Usage
Creating Results (service layer)
using CoreMesh.Result.Extensions;
// Success
return Result<User>.Ok(user);
return Result<User>.Created(user);
return Result.NoContent();
// Failure
return Result<User>.NotFound(new Error("USER_001", "User not found"));
return Result<User>.Forbidden(new Error("AUTH_001", "Access denied"));
return Result<User>.BadRequest(new Error("INPUT_001", "Invalid input"));
// Validation errors
return Result<User>.Invalid(new Dictionary<string, string[]>
{
["Name"] = ["Name is required", "Name too long"],
["Email"] = ["Invalid email format"]
});
Converting to HTTP Response (API layer)
using CoreMesh.Result.Http;
app.MapGet("/users/{id}", async (int id, UserService svc) =>
{
var result = await svc.GetUserAsync(id);
return result.ToHttpResult();
});
File Response
// byte[]
Result<byte[]> result = await fileService.GetPdfAsync(id);
return result.ToFile("application/pdf", "report.pdf");
// Stream
Result<Stream> result = await fileService.GetStreamAsync(id);
return result.ToFile("video/mp4", "video.mp4", enableRangeProcessing: true);
Server-Sent Events
// Simple stream
Result<IAsyncEnumerable<StockPrice>> result = service.GetPriceStream();
return result.ToServerSentEvents(eventType: "price");
// Custom SseItem per event
return result.ToServerSentEvents(() =>
result.Data!.Select(p => new SseItem<StockPrice>(p, eventType: "price")));
Authentication
Result result = await authService.LoginAsync(req);
return result.ToSignIn(principal, authenticationScheme: "Cookies");
Result result = await authService.LogoutAsync();
return result.ToSignOut();
Response Envelope
All responses are wrapped in a consistent ApiResponse envelope.
Success (with data)
{
"isSuccess": true,
"code": "ok",
"data": { "id": 1, "name": "David" }
}
Success (no data)
{
"isSuccess": true,
"code": "ok"
}
Failure
{
"isSuccess": false,
"code": "USER_001",
"problem": {
"status": 404,
"title": "USER_001",
"detail": "User not found"
}
}
Validation Failure (422)
{
"isSuccess": false,
"code": "VALIDATION",
"problem": {
"status": 422,
"title": "VALIDATION",
"detail": "One or more validation errors occurred",
"errors": {
"Name": ["Name is required"],
"Email": ["Invalid email format"]
}
}
}
Status → HTTP Mapping
ResultStatus |
HTTP Status |
|---|---|
Ok |
200 OK |
Created |
201 Created |
NoContent |
204 No Content |
BadRequest |
400 Bad Request |
Forbidden |
403 Forbidden |
NotFound |
404 Not Found |
Invalid |
422 Unprocessable Entity |
Design Notes
- The
Result/Result<T>types have no dependency on ASP.NET Core — they are safe to use in domain or application layers - HTTP concerns (
ApiResponse,TypedResults) are isolated in theCoreMesh.Result.Httpnamespace NoContent,ToFile(),ToServerSentEvents(),ToSignIn(), andToSignOut()do not wrap inApiResponsesince they carry non-JSON payloads or are handled by the auth middlewareResult<T>constructors areprotected— instances can only be created through factory methods inResultExtensions
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CoreMesh.Result:
| Package | Downloads |
|---|---|
|
CoreMesh.Result.AspNetCore
ASP.NET Core integration for CoreMesh.Result – global exception handling, HTTP response conversion, and ApiResponse envelope. |
GitHub repositories
This package is not used by any popular GitHub repositories.