using System.Threading.Tasks;
public interface IRequestHandler
void Handle<TRequest, TResponse>(Func<TRequest, TResponse> handler);
void Handle<TRequest>(Action<TRequest> handler);
void HandleAsync<TRequest, TResponse>(Func<TRequest, Task<TResponse>> handler);
void HandleAsync<TRequest>(Func<TRequest, Task> handler);
public interface IServiceImpelementationProvider<out TServiceContract> where TServiceContract: class
public interface IServerProxyMapper<TServiceContract> where TServiceContract: class
IServiceImpelementationProvider<TServiceContract> ServiceImpelementationProvider { get; set; }
void Map(IRequestHandler requestHandler);
public interface IService
Task Method3(int a, string b);
Task<string> Method4(int a);
public interface IResponse
public class Response: IResponse
public object Value {get; set;}
public interface IMethod1And2And4Request
public interface IMethod3Request
private IServiceImpelementationProvider<IService> _implementation;
public static void Main()
private void Handle1(IMethod1And2And4Request req)
_implementation.Get().Method1(req.a);
private IResponse Handle2(IMethod1And2And4Request req)
Value = _implementation.Get().Method2(req.a)
private Task Handle3(IMethod3Request req)
return _implementation.Get().Method3(req.a, req.b);
private Task<IResponse> Handle4(IMethod1And2And4Request req)
return _implementation.Get().Method4(req.a).ContinueWith(t => (IResponse) new Response() { Value = t.Result });
public void Map(IRequestHandler handler)
handler.Handle<IMethod1And2And4Request>(Handle1);
handler.Handle<IMethod1And2And4Request, IResponse>(Handle2);
handler.HandleAsync<IMethod3Request>(Handle3);
handler.HandleAsync<IMethod1And2And4Request, IResponse>(Handle4);