public TResult Dispatch <TResult>(IAPICommand command)
        {
            var sw             = Stopwatch.StartNew();
            var commandContext = new CommandContext();

            commandContext.CurrentCommand = command;
            using (var childContainer = iocContainer.Clone())
            {
                childContainer.Register(commandContext);
                try
                {
                    OnDispatching(commandContext);
                    var handler = handlers.FindHandler(command.GetType());
                    var result  = (TResult)handler.Execute(ResolveParameters(handler, command, childContainer));
                    OnDispatched(commandContext);
                    // TODO: logging and other instrumentation
                    sw.Stop();
                    return(result);
                }
                catch (Exception e)
                {
                    OnDispatched(commandContext, e);
                    sw.Stop();
                    // TODO: logging
                    throw;
                }
            }
        }
示例#2
0
        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;
                }
            }
        }