Vali-Mediator.AspNetCore
1.0.1
dotnet add package Vali-Mediator.AspNetCore --version 1.0.1
NuGet\Install-Package Vali-Mediator.AspNetCore -Version 1.0.1
<PackageReference Include="Vali-Mediator.AspNetCore" Version="1.0.1" />
<PackageVersion Include="Vali-Mediator.AspNetCore" Version="1.0.1" />
<PackageReference Include="Vali-Mediator.AspNetCore" />
paket add Vali-Mediator.AspNetCore --version 1.0.1
#r "nuget: Vali-Mediator.AspNetCore, 1.0.1"
#:package Vali-Mediator.AspNetCore@1.0.1
#addin nuget:?package=Vali-Mediator.AspNetCore&version=1.0.1
#tool nuget:?package=Vali-Mediator.AspNetCore&version=1.0.1
Vali-Mediator.AspNetCore
ASP.NET Core integration for Vali-Mediator. Maps Result<T> and Result to HTTP responses for both MVC controllers and Minimal API.
Installation
dotnet add package Vali-Mediator.AspNetCore
What it does
Provides two extension methods on Result<T> and Result:
| Method | Use case |
|---|---|
ToActionResult() |
MVC controllers → returns IActionResult |
ToHttpResult() |
Minimal API → returns IResult |
ErrorType → HTTP Status Code Mapping
| ErrorType | HTTP Status |
|---|---|
None (success) |
200 OK (or 204 No Content for non-generic Result) |
Validation |
400 Bad Request |
NotFound |
404 Not Found |
Conflict |
409 Conflict |
Unauthorized |
401 Unauthorized |
Forbidden |
403 Forbidden |
Failure |
500 Internal Server Error |
When Result<T> carries structured ValidationErrors (a dictionary keyed by property name), the 400 response uses ValidationProblemDetails for a structured error body.
Usage: MVC Controllers
using Vali_Mediator.AspNetCore;
using Vali_Mediator.Core.Result;
[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
private readonly IValiMediator _mediator;
public OrdersController(IValiMediator mediator) => _mediator = mediator;
// Result<T> example
[HttpPost]
public async Task<IActionResult> PlaceOrder(PlaceOrderCommand command)
{
Result<string> result = await _mediator.Send(command);
return result.ToActionResult(); // 200 OK with value, or error response
}
// Non-generic Result example (void handler)
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteOrder(string id)
{
Result result = await _mediator.Send(new DeleteOrderCommand { Id = id });
return result.ToActionResult(); // 204 No Content on success, or error response
}
}
Usage: Minimal API
using Vali_Mediator.AspNetCore;
using Vali_Mediator.Core.Result;
var app = builder.Build();
// Result<T> example
app.MapPost("/api/orders", async (PlaceOrderCommand command, IValiMediator mediator) =>
{
Result<string> result = await mediator.Send(command);
return result.ToHttpResult(); // IResult: 200 OK, or structured error
});
// Non-generic Result example
app.MapDelete("/api/orders/{id}", async (string id, IValiMediator mediator) =>
{
Result result = await mediator.Send(new DeleteOrderCommand { Id = id });
return result.ToHttpResult(); // IResult: 204 No Content, or structured error
});
Validation Errors
When a Result<T> is created with structured validation errors via Result<T>.Fail(Dictionary<string, List<string>> errors, ErrorType.Validation), the 400 response returns a ValidationProblemDetails body:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"Name": ["'Name' must not be empty."],
"Price": ["'Price' must be greater than 0."]
}
}
Donations
If Vali-Mediator is useful to you, consider supporting its development:
- Latin America — MercadoPago
- International — PayPal
License
Contributions
Issues and pull requests are welcome on GitHub.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 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. |
-
net7.0
- Vali-Mediator (>= 2.0.1)
-
net8.0
- Vali-Mediator (>= 2.0.1)
-
net9.0
- Vali-Mediator (>= 2.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.1 — Documentation: enabled XML documentation file for full IntelliSense support.
v1.0.0 — Initial release.
- ResultExtensions: ToActionResult() maps Result<T> to IActionResult.
- ResultExtensions: ToHttpResult() maps Result<T> to IResult (Minimal API).
- ResultExtensions: ToActionResult() and ToHttpResult() for non-generic Result.
- ErrorType mapping: None/Ok→200, Validation→400, NotFound→404, Conflict→409, Unauthorized→401, Forbidden→403, Failure→500.
- Structured validation errors (ValidationErrors dictionary) returned as ValidationProblemDetails.