Re.MediatR
12.1.0
dotnet add package Re.MediatR --version 12.1.0
NuGet\Install-Package Re.MediatR -Version 12.1.0
<PackageReference Include="Re.MediatR" Version="12.1.0" />
<PackageVersion Include="Re.MediatR" Version="12.1.0" />
<PackageReference Include="Re.MediatR" />
paket add Re.MediatR --version 12.1.0
#r "nuget: Re.MediatR, 12.1.0"
#:package Re.MediatR@12.1.0
#addin nuget:?package=Re.MediatR&version=12.1.0
#tool nuget:?package=Re.MediatR&version=12.1.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:
// 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 | Versions 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. |
-
net9.0
- MediatR (>= 12.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.