Skip to content

Instantly share code, notes, and snippets.

@kdowswell
Created August 13, 2016 17:04
Show Gist options
  • Save kdowswell/32d3a8e16136cd1f7ff6a9c290fdb487 to your computer and use it in GitHub Desktop.
Save kdowswell/32d3a8e16136cd1f7ff6a9c290fdb487 to your computer and use it in GitHub Desktop.
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