Created
August 13, 2016 17:04
-
-
Save kdowswell/32d3a8e16136cd1f7ff6a9c290fdb487 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Mediator : IMediator | |
{ | |
private readonly IContainer _container; | |
public Mediator(IContainer container) | |
{ | |
_container = container; | |
} | |
public void Send<TCommand>(TCommand command) where TCommand : ICommand | |
{ | |
var handlerType = | |
typeof(ICommandHandler<>).MakeGenericType(command.GetType()); | |
dynamic handler = _container.GetInstance(handlerType); | |
handler.Handle((dynamic)command); | |
} | |
public TResult Send<TResult>(object query) | |
{ | |
var handlerType = | |
typeof (IQueryHandler<,>).MakeGenericType(query.GetType(), typeof (TResult)); | |
dynamic handler = _container.GetInstance(handlerType); | |
return handler.Handle((dynamic)query); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment