MediatR.Extensions.RPC.Core
1.0.0
See the version list below for details.
dotnet add package MediatR.Extensions.RPC.Core --version 1.0.0
NuGet\Install-Package MediatR.Extensions.RPC.Core -Version 1.0.0
<PackageReference Include="MediatR.Extensions.RPC.Core" Version="1.0.0" />
<PackageVersion Include="MediatR.Extensions.RPC.Core" Version="1.0.0" />
<PackageReference Include="MediatR.Extensions.RPC.Core" />
paket add MediatR.Extensions.RPC.Core --version 1.0.0
#r "nuget: MediatR.Extensions.RPC.Core, 1.0.0"
#:package MediatR.Extensions.RPC.Core@1.0.0
#addin nuget:?package=MediatR.Extensions.RPC.Core&version=1.0.0
#tool nuget:?package=MediatR.Extensions.RPC.Core&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. net9.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MediatR.Extensions.RPC.Core:
Package | Downloads |
---|---|
MediatR.Extensions.RPC.AspNetCore
MediatR extension for automatically expose your MediatR requests as Remote Procedure Call (RPC) like endpoints. |
|
MediatR.Extensions.RPC.Azure.Functions
MediatR extension for integrating with Azure functions. Supports HTTP functions. |
GitHub repositories
This package is not used by any popular GitHub repositories.