Re.MediatR
12.0.0
dotnet add package Re.MediatR --version 12.0.0
NuGet\Install-Package Re.MediatR -Version 12.0.0
<PackageReference Include="Re.MediatR" Version="12.0.0" />
paket add Re.MediatR --version 12.0.0
#r "nuget: Re.MediatR, 12.0.0"
// 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 | Versions 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. |
-
net8.0
- MediatR (>= 12.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.