Re.MediatR 12.0.0

dotnet add package Re.MediatR --version 12.0.0
NuGet\Install-Package Re.MediatR -Version 12.0.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.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Re.MediatR --version 12.0.0
#r "nuget: Re.MediatR, 12.0.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.
// Install Re.MediatR as a Cake Addin
#addin nuget:?package=Re.MediatR&version=12.0.0

// Install Re.MediatR as a Cake Tool
#tool nuget:?package=Re.MediatR&version=12.0.0

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:

app.UseEndpoints(endpoints =>
{
    endpoints.MapReMediatR<PingRequest>("/mediatr");
});

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 PingResponse()
    {
        Time = DateTime.Now;
    }

    public DateTime Time { get; }
}

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"
}
Product 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. 
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.0.0 90 4/12/2024
1.0.1 292 9/21/2022
1.0.0 168 9/21/2022