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
                    
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="Vali-Mediator.AspNetCore" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Vali-Mediator.AspNetCore" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Vali-Mediator.AspNetCore" />
                    
Project file
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 Vali-Mediator.AspNetCore --version 1.0.1
                    
#r "nuget: Vali-Mediator.AspNetCore, 1.0.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 Vali-Mediator.AspNetCore@1.0.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=Vali-Mediator.AspNetCore&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Vali-Mediator.AspNetCore&version=1.0.1
                    
Install as a Cake Tool

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:


License

Apache License 2.0

Contributions

Issues and pull requests are welcome on GitHub.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1 86 3/18/2026
1.0.0 88 3/16/2026

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.