Linger.Results.AspNetCore
1.3.1-preview
See the version list below for details.
dotnet add package Linger.Results.AspNetCore --version 1.3.1-preview
NuGet\Install-Package Linger.Results.AspNetCore -Version 1.3.1-preview
<PackageReference Include="Linger.Results.AspNetCore" Version="1.3.1-preview" />
<PackageVersion Include="Linger.Results.AspNetCore" Version="1.3.1-preview" />
<PackageReference Include="Linger.Results.AspNetCore" />
paket add Linger.Results.AspNetCore --version 1.3.1-preview
#r "nuget: Linger.Results.AspNetCore, 1.3.1-preview"
#:package Linger.Results.AspNetCore@1.3.1-preview
#addin nuget:?package=Linger.Results.AspNetCore&version=1.3.1-preview&prerelease
#tool nuget:?package=Linger.Results.AspNetCore&version=1.3.1-preview&prerelease
Linger.Results.AspNetCore
Linger.Results.AspNetCore provides extension methods that seamlessly integrate the Linger.Results library with ASP.NET Core framework, allowing API controllers to easily return results in a unified format.
Features
- Elegantly convert
ResultandResult<T>objects to ASP.NET CoreActionResult - Support for Minimal API - convert
ResultandResult<T>toIResultusing modernResultsstatic class - Automatically select appropriate HTTP status codes based on result status
- Support for custom success and failure status codes
- Provide RFC 7807 standard ProblemDetails format output
Supported Framework Versions
- .NET 8.0+
Installation
dotnet add package Linger.Results.AspNetCore
Basic Usage
Using in Controllers
[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
[HttpGet("{id}")]
public async Task<ActionResult<UserDto>> GetUser(int id)
{
var result = await _userService.GetUserByIdAsync(id);
return result.ToActionResult(); // Success returns UserDto, failure returns error array
}
[HttpPost]
public async Task<ActionResult<UserDto>> CreateUser(CreateUserRequest request)
{
var result = await _userService.CreateUserAsync(request);
return result.ToActionResult(HttpStatusCode.Created);
}
[HttpDelete("{id}")]
public async Task<ActionResult> DeleteUser(int id)
{
var result = await _userService.DeleteUserAsync(id);
return result.ToProblemDetails(); // Use RFC 7807 format
}
}
Using in Minimal API
var app = WebApplication.Create();
app.MapGet("/api/users/{id}", async (int id, IUserService userService) =>
{
var result = await userService.GetUserByIdAsync(id);
return result.ToHttpResult(); // Automatic status code mapping
});
app.MapPost("/api/users", async (CreateUserRequest request, IUserService userService) =>
{
var result = await userService.CreateUserAsync(request);
return result.ToHttpResult(HttpStatusCode.Created);
});
app.MapDelete("/api/users/{id}", async (int id, IUserService userService) =>
{
var result = await userService.DeleteUserAsync(id);
return result.ToNoContentResult(); // Success returns 204 No Content
});
API Method Comparison
| Scenario | Controller API | Minimal API |
|---|---|---|
| Basic conversion | result.ToActionResult() |
result.ToHttpResult() |
| Custom success code | result.ToActionResult(HttpStatusCode.Created) |
result.ToHttpResult(HttpStatusCode.Created) |
| Custom both codes | result.ToActionResult(HttpStatusCode.Created, HttpStatusCode.BadRequest) |
result.ToHttpResult(HttpStatusCode.Created, HttpStatusCode.BadRequest) |
| Created response | result.ToActionResult(HttpStatusCode.Created) |
result.ToCreatedResult("/api/users/123") |
| No content response | result.ToActionResult(HttpStatusCode.NoContent) |
result.ToNoContentResult() |
| Problem details | result.ToProblemDetails() |
result.ToHttpResult() (uses ProblemDetails automatically) |
Status code parameters use the
System.Net.HttpStatusCodeenum for type safety and IDE IntelliSense. When using overloads with onlysuccessStatusCode, the failure status code is automatically determined based onResult.Status(e.g.,NotFound→ 404, others → 400).
Response Format Examples
Success Responses
// Result<UserDto> success
{
"id": 123,
"name": "John Doe",
"email": "john.doe@example.com"
}
// Result success
{
"status": "Ok",
"isSuccess": true,
"isFailure": false,
"errors": []
}
Failure Responses
// Standard error format
[
{
"code": "User.NotFound",
"message": "User with ID 123 not found"
}
]
// ProblemDetails format (ToProblemDetails())
{
"type": null,
"title": "One or more validation errors occurred",
"status": 400,
"detail": "Email format is invalid; Password strength is insufficient",
"errors": {
"User.InvalidEmail": "Email format is invalid",
"User.WeakPassword": "Password strength is insufficient"
}
}
Note: errors is an RFC 7807 extension member. The server adds it via ProblemDetails.Extensions["errors"]. ASP.NET Core serializes Extensions entries as top-level properties, so you will see a top-level errors field. This is compliant with RFC 7807's extension mechanism.
Status Code Mapping
Result.Success()→ 200 OKResult.NotFound()→ 404 Not FoundResult.Failure()→ 400 Bad Request
Best Practices
- Separation of Concerns: Service layer returns
Result, controller handles HTTP response conversion - Consistent API Responses: Maintain unified error formats across the application
- Use ProblemDetails: Prefer RFC 7807 format for client-facing APIs
- Choose Right API Style: Use Controllers for complex scenarios, Minimal API for simple cases
Using with Linger.Results
This library is an extension of Linger.Results. Please also refer to the Linger.Results documentation to learn more about result object functionality.
| 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 is compatible. 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 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
- Linger.Results (>= 1.3.1-preview)
-
net8.0
- Linger.Results (>= 1.3.1-preview)
-
net9.0
- Linger.Results (>= 1.3.1-preview)
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.6.4 | 42 | 8/16/2026 |
| 1.6.3 | 102 | 8/5/2026 |
| 1.6.2 | 114 | 8/2/2026 |
| 1.6.0 | 108 | 7/25/2026 |
| 1.5.5 | 107 | 7/23/2026 |
| 1.5.4-preview | 80 | 7/21/2026 |
| 1.5.3-preview | 96 | 7/20/2026 |
| 1.5.2-preview | 95 | 7/19/2026 |
| 1.5.1-preview | 94 | 7/15/2026 |
| 1.5.0-preview | 88 | 7/14/2026 |
| 1.4.4-preview | 108 | 6/16/2026 |
| 1.4.3-preview | 99 | 6/15/2026 |
| 1.4.2 | 118 | 5/20/2026 |
| 1.4.1-preview | 105 | 5/12/2026 |
| 1.4.0 | 111 | 5/6/2026 |
| 1.3.3-preview | 88 | 5/5/2026 |
| 1.3.2-preview | 109 | 4/29/2026 |
| 1.3.1-preview | 106 | 4/28/2026 |
| 1.3.0-preview | 104 | 4/27/2026 |
| 1.2.0-preview | 113 | 3/29/2026 |