MediatR.Extensions.RPC.AspNetCore
1.0.0
See the version list below for details.
dotnet add package MediatR.Extensions.RPC.AspNetCore --version 1.0.0
NuGet\Install-Package MediatR.Extensions.RPC.AspNetCore -Version 1.0.0
<PackageReference Include="MediatR.Extensions.RPC.AspNetCore" Version="1.0.0" />
paket add MediatR.Extensions.RPC.AspNetCore --version 1.0.0
#r "nuget: MediatR.Extensions.RPC.AspNetCore, 1.0.0"
// Install MediatR.Extensions.RPC.AspNetCore as a Cake Addin #addin nuget:?package=MediatR.Extensions.RPC.AspNetCore&version=1.0.0 // Install MediatR.Extensions.RPC.AspNetCore as a Cake Tool #tool nuget:?package=MediatR.Extensions.RPC.AspNetCore&version=1.0.0
MediatR-RPC
Automatically expose your MediatR requests as Remote Procedure Call (RPC) like endpoints.
Introduction
MediatR is a simple, unambitious mediator implementation in .NET made by Jimmy Bogard. MediatR-RPC is an extension library aims to automatically expose endpoints to process the Requests using configuration.
When configurating MediatR-RPC all configurations needs to be explicitly set. This way it is more clear for the reader what is going and what the expected behaviors are. Altought there are no implicit defaults there are some predefined configurations helpers available ready to use.
Getting started in ASP.NET Core
In ASP.NET Core MediatR-RPC will configure itself as an EndpointMiddleware with a single templated route that only allows POST method, example:
https://localhost:44393/rpc/{requestName}
Install package from Nuget:
Install-Package MediatR.Extensions.RPC.AspNetCore
First register MediatR-RPC when configurating the service by using the .AddMediatrRpc(...)
extension method on the service collection:
public void ConfigureServices(IServiceCollection services)
{
// Additional configuration
var targetAssembly = this.GetType().Assembly;
services.AddMediatR(targetAssembly);
services.AddMediatrRpc(o =>
{
o.ScanRequests(targetAssembly);
o.UseRequestNameMatchingConvention();
});
// Additional configuration
}
In ASP.NET Core MediatR-RPC configures an EndpointMiddleware by applying the .MapRpc(...)
extension method on the endpoints configuration:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Additional configuration
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapRpc(o =>
{
o.Path = "rpc";
o.SerializeWithSystemJson(new System.Text.Json.JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
o.ResponsesAs200Ok();
o.UnmatchedRequestsAs404NotFound();
});
});
// Additional configuration
}
Configuration
MediatR-RPC in its core is about matching a name with a corresponding request type that can be constructed and process by MediatR. This core feature is then applied on different hosting applications. In ASP.NET Core an EndpointMiddleware is configured so a name and properties can be extracted from HTTP request messages.
There are two parts of configurating MediatR-RCP. First configure which requests that are available and how they are mapped. This is done in .AddMediatrRpc(...)
extenstion method and applying the RpcOptions
. Second, depending on the host application, the endpoints are configured.
RpcOptions
Property | Description |
---|---|
Requests | A collection of MediatR requests that are available for matching. |
MatchingConvention | Given a request which matching name should be derived from it. |
Helping methods | Description |
---|---|
ScanRequests() | Scans MediatR requests in the specified assmeblies. |
UseRequestNameMatchingConvention() | The request class name is used when matching types. |
RpcEndpointOptions in ASP.NET Core
Property | Description |
---|---|
Path | The URL root path for the endpoint. |
DeserializeRequest | Deserializes the HTTP request body. |
SerializeResponse | Seserializes the MediatR response to the HTTP response body. |
UnmatchedRequest | Handler for unmatched requests. |
HandlResponse | Handler for matched requests. |
Helping methods | Description |
---|---|
SerializeWithSystemJson() | Serialize and Deserialize HTTP body as JSON. |
UnmatchedRequestsAs404NotFound() | Unmatched requests are returned as 404 - NotFound HTTP responses. |
ResponsesAs200Ok() | Matched requests are returned as 200 - OK HTTP responses. |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- MediatR.Extensions.Microsoft.DependencyInjection (>= 9.0.0)
- MediatR.Extensions.RPC.Core (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.