Beispiel #1
0
 internal IEnumerable <RequestHandlerAsync <TRequest> > GetAsyncHandlers()
 {
     return(new AsyncRequestHandlers <TRequest>(
                _registry.Get <TRequest>()
                .Select(handlerType => _asyncHandlerFactory.Create(handlerType))
                .Cast <IHandleRequestsAsync <TRequest> >()));
 }
        /// <summary>
        /// Creates the async request handler.
        /// </summary>
        /// <returns><see cref="IHandleRequestsAsync{TRequest}"/>.</returns>
        public IHandleRequestsAsync <TRequest> CreateAsyncRequestHandler()
        {
            var handlerType = _attribute.GetHandlerType().MakeGenericType(_messageType);
            var handler     = (IHandleRequestsAsync <TRequest>)_factory.Create(handlerType);

            //Lod the context before the initializer - in case we want to use the context from within the initializer
            handler.Context = _requestContext;
            handler.InitializeFromAttributeParams(_attribute.InitializerParams());
            return(handler);
        }
Beispiel #3
0
        /// <summary>
        /// Creates the async request handler.
        /// </summary>
        /// <param name="factory">The async handler factory.</param>
        /// <param name="attribute">The attribute.</param>
        /// <param name="requestContext">The request context.</param>
        /// <returns><see cref="IHandleRequestsAsync{TRequest}"/>.</returns>
        public static IHandleRequestsAsync <TRequest> CreateAsyncRequestHandler <TRequest>(this IAmAHandlerFactoryAsync factory, RequestHandlerAttribute attribute, IRequestContext requestContext)
            where TRequest : class, IRequest
        {
            var handlerType = attribute.GetHandlerType().MakeGenericType(typeof(TRequest));
            var handler     = (IHandleRequestsAsync <TRequest>)factory.Create(handlerType);

            //Lod the context before the initializer - in case we want to use the context from within the initializer
            handler.Context = requestContext;
            handler.InitializeFromAttributeParams(attribute.InitializerParams());
            return(handler);
        }
Beispiel #4
0
        /// <summary>
        /// Creates the async request handler.
        /// </summary>
        /// <param name="factory">The async handler factory.</param>
        /// <param name="attribute">The attribute.</param>
        /// <param name="requestContext">The request context.</param>
        /// <returns><see cref="IHandleRequestsAsync{TRequest}"/>.</returns>
        public static IHandleRequestsAsync <TRequest> CreateAsyncRequestHandler <TRequest>(this IAmAHandlerFactoryAsync factory, RequestHandlerAttribute attribute, IRequestContext requestContext)
            where TRequest : class, IRequest
        {
            var handlerType = attribute.GetHandlerType().MakeGenericType(typeof(TRequest));
            var handler     = (IHandleRequestsAsync <TRequest>)factory.Create(handlerType);

            if (handler is null)
            {
                throw new ConfigurationException($"Could not create handler {handlerType} from {factory}");
            }
            //Load the context before the initializer - in case we want to use the context from within the initializer
            handler.Context = requestContext;
            handler.InitializeFromAttributeParams(attribute.InitializerParams());
            return(handler);
        }