Etymon.Result.Extensions
1.3.0
dotnet add package Etymon.Result.Extensions --version 1.3.0
NuGet\Install-Package Etymon.Result.Extensions -Version 1.3.0
<PackageReference Include="Etymon.Result.Extensions" Version="1.3.0" />
<PackageVersion Include="Etymon.Result.Extensions" Version="1.3.0" />
<PackageReference Include="Etymon.Result.Extensions" />
paket add Etymon.Result.Extensions --version 1.3.0
#r "nuget: Etymon.Result.Extensions, 1.3.0"
#:package Etymon.Result.Extensions@1.3.0
#addin nuget:?package=Etymon.Result.Extensions&version=1.3.0
#tool nuget:?package=Etymon.Result.Extensions&version=1.3.0
Etymon.Result.Extensions
Etymon.Result.Extensions provides helper extensions for working with Etymon.Result, specifically for ASP.NET Core Web APIs. It simplifies controller code by converting Result<T>
objects into appropriate HTTP responses using ToActionResult()
or ToActionResultWithResult()
.
📦 Installation
dotnet add package Etymon.Result.Extensions
Requires:
.NET 6.0
or higher and reference toEtymon.Result
.
✨ Features
ToActionResult()
for returningIActionResult
in responsesToActionResultWithResult()
for returning fullActionResult<Result<T>>
object in responses- Maps
ResultCode
(e.g.NotFound
,ValidationError
) to standard HTTP responses - Reduces repetitive error handling logic in controller actions
✅ How to Use
1. Add a reference to your service that returns Result<T>
:
public async Task<Result<ItemDto>> GetItem(int id);
2. In your controller:
Using ToActionResult()
(returns IActionResult
)
using Etymon.Result.Extensions;
[HttpGet("{id}")]
public async Task<IActionResult> GetItem(int id)
{
var result = await _itemService.GetItem(id);
return result.ToActionResult();
}
Using ToActionResultWithResult()
(returns full ActionResult<Result<T>>
in responses)
[HttpGet("{id}")]
public async Task<ActionResult<Result<ItemDto>>> GetItem(int id)
{
var result = await _itemService.GetItem(id);
return result.ToActionResultWithResult();
}
3. Output Samples
✅ Success (HTTP 200):
{
"data": {
"id": 1,
"name": "Sample Item"
},
"error": null,
"isSuccess": true
}
❌ Failure (e.g. HTTP 404):
{
"data": null,
"error": {
"code": "NotFound",
"message": "Item was not found."
},
"isSuccess": false
}
🔧 How It Works
The ToActionResult()
and ToActionResultWithResult()
methods map ResultCode
to standard HTTP results:
ResultCode |
HTTP Response |
---|---|
Success |
200 OK |
NotFound |
404 Not Found |
ValidationError |
400 Bad Request |
Unauthorized |
403 Forbidden |
Conflict |
409 Conflict |
InternalError |
500 Internal Error |
📌 Version History
- 1.3.0
- Added
ToActionResultWithResult()
to support fullActionResult<Result<T>>
responses
- Added
- 1.2.1 and earlier
- Core implementation of
ToActionResult()
with clean HTTP response mappings
- Core implementation of
📄 License
MIT
🤝 Contributing
Feel free to open issues or submit PRs to extend support for non-generic Result
, middleware integration, or advanced model binding.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Etymon.Result (>= 1.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.