Re.MediatR 12.1.0

dotnet add package Re.MediatR --version 12.1.0
                    
NuGet\Install-Package Re.MediatR -Version 12.1.0
                    
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="Re.MediatR" Version="12.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Re.MediatR" Version="12.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Re.MediatR" />
                    
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 Re.MediatR --version 12.1.0
                    
#r "nuget: Re.MediatR, 12.1.0"
                    
#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 Re.MediatR@12.1.0
                    
#: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=Re.MediatR&version=12.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Re.MediatR&version=12.1.0
                    
Install as a Cake Tool

Re.MediatR

Exposes MediatR trough a Web-API endpoint for SPA applications (Angular, React, Vue, ...)

You can now use MediatR without having to write your own API Controllers

Works with net6.0 only at the moment

Just register the middleware and you can start calling MediatR from inside your favorite SPA framework

Installing Re.MediatR

You should install Re.MediatR with NuGet:

Install-Package Re.MediatR

Or via the .NET Core command line interface:

dotnet add package Re.MediatR

Usage

Just add ReMediatR as a new endpoint during runtime configuration:

// Map ReMediatr with the default URL '/mediatr', register all requests in the current executing assembly
app.MapReMediatR();

Where PingRequest is a generic type for which ReMediatR will scan the assembly of that type

Given this MediatR request-handler:


using System;
using System.Threading;
using System.Threading.Tasks;

namespace MyApp.RequestHandlers;

public class PingRequest : IRequest<PingResponse>
{
    public string Hello { get; set; }
}

public class PingResponse
{
    public DateTime Time { get; } = DateTime.Now;
}

public class PingRequestHandler : IRequestHandler<PingRequest, PingResponse>
{
    public override Task<PingResponse> Handle(PingRequest request, CancellationToken token)
    {
        return Task.FromResult(new PingResponse());
    }
}

The handler is now available trough a HTTP-post request, if your dotnet app is running on localhost:5001 write


POST http://localhost:5001/mediatr?type=MyApp.RequestHandlers.PingRequest
Content-Type: application/json

{
  "hello": "world"
}

Response


HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: xy

{
  "time": "2022-02-13T15:31:55.559Z"
}

Options

When setting up ReMediatR, you can change the name of the endpoint 'mediatr' to something else, and you can change additional settings.


app.MapReMediatR("/mediatr", o => o
    .RequestAssembly(typeof(PingRequest).Assembly) // Provide another assembly that contains the requests
    .IndexFullNameInTypeCache() // Index all requests with their fully qualified type name, including the namespace
);
Product Compatible and additional computed target framework versions.
.NET 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
12.1.0 225 4/15/2025
12.0.0 180 4/12/2024
1.0.1 390 9/21/2022
1.0.0 267 9/21/2022