Skip to content

Run your MediatR requests and commands from a remote client

License

Notifications You must be signed in to change notification settings

kevinarthurackerman/RemotiatR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RemotiatR

MediatR For Your Remote Clients

RemotiatR makes it easy to run you MediatR requests and commands from a remote client on your server without all the ceremony. Just send or publish the same way you always would, and RemotiatR handles everything between.

RemotiatR is not made in direct affiliation or endorsement of the authors or maintainers of any other libraries

Install Packages

To add RemotiatR to your project add the client and server packages to your respective client and server projects

dotnet add package RemotiatR.Client
dotnet add package RemotiatR.Server

Getting Started

Check out the example at src/Example/

In your shared project

using MediatR;

public class Ping
{
    public class Request : IRequest<Response>
    {
    }

    public class Response
    {
        public DateTime ServerTime { get; set; }
    }
}

On your server

using RemotiatR.Server;
using RemotiatR.MessageTransport.Http.Server;
using RemotiatR.Serializer.Json.Server;

public class Startup
{
    ...
    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddRemotiatr(x => 
        {
            // register host uri and assemblies to search for notifications and requests
            x.AddHost(new Uri("https://localhost:44337", UriKind.Absolute), typeof(Ping).Assembly, typeof(Startup).Assembly);
			
            // register http message transport
            x.AddHttpMessageTransport();
            
            // register json serializer
            x.AddJsonSerializer();
        }
    }
    ...
    public void Configure(IApplicationBuilder app)
    {
        ...
        // uses the registered transport
        app.UseHttpRemotiatr();
    }
}

public class PingHandler : IRequestHandler<Ping.Request, Ping.Response>
{
    public Task<Response> Handle(Request request, CancellationToken cancellationToken) =>
        Task.FromResult(new Response { ServerTime = DateTime.UtcNow });
}

On your client

using RemotiatR.Client;
using RemotiatR.MessageTransport.Http.Client;
using RemotiatR.Serializer.Json.Client;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddRemotiatr(x =>
        {
            // register host uri and assemblies to search for notifications and requests
            x.AddHost(new Uri("https://localhost:44337", UriKind.Absolute), typeof(Ping).Assembly, typeof(Startup).Assembly);
			
            // register http message transport
            x.AddHttpMessageTransport();
            
            // register json serializer
            x.AddJsonSerializer();
        });
    }
    ...
}

public class ServerTimeService
{
    private readonly IRemotiatr _remotiatr;

    public ServerTimeService(IRemotiatr remotiatr) =>
        _remotiatr = remotiatr;

    public async Task<DateTime> GetServerTime() =>
        (await _remotiatr.Send(new Ping.Request())).ServerTime;
}

Extensions

Adding support for HTTP

Adding support for JSON

Adding support for FluentValidation

Contributing

Want to contribute? Great!

Check out the setup docs to get started

If you are creating an extension check out the Extension Template

License

MIT

About

Run your MediatR requests and commands from a remote client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published