Esempio n. 1
0
        protected virtual TReply InvokeHandlerMethod <TReply>(RequestHandlerInfo handlerInfo, params object[] parameters)
        {
            if (handlerInfo == null)
            {
                throw new ArgumentNullException("handlerInfo");
            }

            var result = handlerInfo.Method.Invoke(handlerInfo.HandlerInstance, parameters);

            return((TReply)result);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the Handle() method for the given type of request.
        /// </summary>
        /// <typeparam name="TReply">Reply type.</typeparam>
        /// <param name="request">Request.</param>
        /// <returns>Request handler info.</returns>
        public RequestHandlerInfo GetHandlerMethod <TReply>(IRequest <TReply> request)
        {
            Type requestType = request.GetType();
            Type replyType   = typeof(TReply);

            try
            {
                RequestHandlerInfo requestHandlerInfo = GetRequestHandlerInfo(typeof(IRequestHandler <,>), requestType, replyType);
                requestHandlerInfo.HandlerInstance = _resolver.GetInstanceOfHandler(requestHandlerInfo.GenericType);
                return(requestHandlerInfo);
            }
            catch (Exception e)
            {
                var message = string.Format("Unable to resolve request.\nRequested type: {0}\nRequest: {1}", typeof(IRequest <TReply>), request);
                throw new UnableToResolveRequestException(message, e);
            }
        }