Giter Site home page Giter Site logo

funclun / remotiatr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kevinarthurackerman/remotiatr

0.0 1.0 0.0 713 KB

Run your MediatR requests and commands from a remote client

C# 71.23% HTML 23.03% CSS 1.65% PowerShell 1.57% JavaScript 0.01% TSQL 2.51%

remotiatr's Introduction

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.

Install Packages

Base nuget packages

Add support for FluentValidation (see https://github.com/FluentValidation/FluentValidation)

Getting Started

In your shared project

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

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

On your server

public class Startup
{
    ...
    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddRemotiatr(x => 
        {
            // register assemblies to search for notifications and requests
            x.AddAssemblies(typeof(PingHandler),typeof(Startup)));
            
            // optional: adds other services registered before this point
            foreach (var service in services) x.Services.Add(service);
        }
    }
    ...
    public void Configure(IApplicationBuilder app)
    {
        ...
        app.UseRemotiatr();
    }
}

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

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddRemotiatr(x =>
        {
            // register assemblies to search for notifications and requests
            x.AddAssemblies(typeof(Ping));
            
            // set the uri to send requests to
            x.SetEndpointUri(new Uri("https://localhost:{{port number}}/remotiatr"));
            
            // optional: adds other services registered before this point
            foreach (var service in services) x.Services.Add(service);
        });
    }
    ...
}

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;
}

Contributing

Want to contribute? Great!

License

MIT

remotiatr's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.