public HandlerFactory(RequestHandlerAttribute attribute, IAmAHandlerFactorySync factorySync, IRequestContext requestContext) { _attribute = attribute; _factorySync = factorySync; _requestContext = requestContext; _messageType = typeof(TRequest); }
private static void PushOntoAttributeList(ref IOrderedEnumerable <RequestHandlerAttribute> preAttributes, RequestHandlerAttribute requestHandlerAttribute) { var attributeList = new List <RequestHandlerAttribute>(); attributeList.Add(requestHandlerAttribute); preAttributes.Each(handler => { handler.Step++; attributeList.Add(handler); }); preAttributes = attributeList.OrderByDescending(handler => handler.Step); }
/// <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); }
/// <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); }