Created
April 4, 2011 02:10
-
-
Save mhinze/901045 to your computer and use it in GitHub Desktop.
over doing it....
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 Querier : IQuerier | |
{ | |
readonly IContainer _container; | |
public Querier(IContainer container) | |
{ | |
_container = container; | |
} | |
public T GetResult<T>(IQuery<T> query) | |
{ | |
var type = typeof (IQueryHandler<,>).MakeGenericType(query.GetType(), typeof (T)); | |
var queryHandler = _container.GetInstance(type); | |
var helper = typeof (Helper<,>).MakeGenericType(query.GetType(), typeof (T)); | |
return (T) ((Helper) Activator.CreateInstance(helper)).ExecuteHandler(queryHandler, query); | |
} | |
interface Helper | |
{ | |
object ExecuteHandler(object handler, object query); | |
} | |
class Helper<TQuery, TResult> : Helper where TQuery : IQuery<TResult> | |
{ | |
public object ExecuteHandler(object handler, object query) | |
{ | |
return ((IQueryHandler<TQuery, TResult>) handler).Execute((TQuery) query); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment