public TResult Dispatch <TResult>(IAPIQuery <TResult> query, QueryScope queryScope) { var sw = Stopwatch.StartNew(); var queryContext = new QueryContext(); queryContext.CurrentQuery = query; queryContext.QueryScope = queryScope; using (var childContainer = iocContainer.Clone()) { childContainer.Register(queryContext); try { OnDispatching(queryContext); var handler = handlers.FindHandler(query.GetType()); var result = (TResult)handler.Execute(ResolveParameters(handler, query, childContainer)); OnDispatched(queryContext); // TODO: logging and other instrumentation sw.Stop(); return(result); } catch (Exception e) { OnDispatched(queryContext, e); sw.Stop(); // TODO: logging throw; } } }
public TResult Query <TResult>(IAPIQuery <TResult> query) { var disposeQueryScope = false; if (currentQueryScope == null) { currentQueryScope = QueryScope(); disposeQueryScope = true; } try { return(queryDispatcher.Dispatch(query, currentQueryScope)); } finally { if (disposeQueryScope) { currentQueryScope.Dispose(); currentQueryScope = null; } } }