Skip to content

Instantly share code, notes, and snippets.

@farhad-taran
Created June 11, 2016 12:24
Show Gist options
  • Save farhad-taran/703a5ddbab93ac0695e45c29f9a1f785 to your computer and use it in GitHub Desktop.
Save farhad-taran/703a5ddbab93ac0695e45c29f9a1f785 to your computer and use it in GitHub Desktop.
public interface IQuery<TResult>
{
}
public interface IQueryHandler<TQuery, TResult> where TQuery : IQuery<TResult>
{
TResult Handle(TQuery query);
}
public interface IQueryProcessor
{
TResult Process<TResult>(IQuery<TResult> query);
}
sealed class QueryProcessor : IQueryProcessor
{
private readonly Container container;
public QueryProcessor(Container container)
{
this.container = container;
}
[DebuggerStepThrough]
public TResult Process<TResult>(IQuery<TResult> query)
{
var handlerType =
typeof(IQueryHandler<,>).MakeGenericType(query.GetType(), typeof(TResult));
dynamic handler = container.GetInstance(handlerType);
return handler.Handle((dynamic)query);
}
}
public interface ICommandHandler<TCommand>
{
void Handle(TCommand command);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment