예제 #1
0
 public PipelineBuilder(IAmASubscriberRegistry registry, IAmAHandlerFactoryAsync asyncHandlerFactory, ILog logger)
 {
     _asyncHandlerFactory = asyncHandlerFactory;
     _logger        = logger;
     _instanceScope = new LifetimeScope(asyncHandlerFactory);
     _interpreter   = new Interpreter <TRequest>(registry, asyncHandlerFactory);
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncHandlerFactory{TRequest}"/> class.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <param name="factory">The async handler factory.</param>
 /// <param name="requestContext">The request context.</param>
 public AsyncHandlerFactory(RequestHandlerAttribute attribute, IAmAHandlerFactoryAsync factory, IRequestContext requestContext)
 {
     _attribute      = attribute;
     _factory        = factory;
     _requestContext = requestContext;
     _messageType    = typeof(TRequest);
 }
 /// <summary>
 /// Supplies the specified handler configuration, so that we can register subscribers and the handler factory used to create instances of them
 /// </summary>
 /// <param name="handlerConfiguration">The handler configuration.</param>
 /// <returns>INeedPolicy.</returns>
 public INeedPolicy Handlers(HandlerConfiguration handlerConfiguration)
 {
     _registry            = handlerConfiguration.SubscriberRegistry;
     _handlerFactory      = handlerConfiguration.HandlerFactory;
     _asyncHandlerFactory = handlerConfiguration.AsyncHandlerFactory;
     return(this);
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when no task queue support is required and only async handlers are used
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IAmAPolicyRegistry policyRegistry)
     : this(subscriberRegistry, asyncHandlerFactory, requestContextFactory, policyRegistry, LogProvider.GetCurrentClassLogger())
 {
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when no task queue support is required
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="handlerFactory">The handler factory.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactory handlerFactory,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IAmAPolicyRegistry policyRegistry)
     : this(subscriberRegistry, handlerFactory, asyncHandlerFactory, requestContextFactory, policyRegistry, LogProvider.For <CommandProcessor>())
 {
 }
예제 #6
0
 public PipelineBuilder(
     IAmASubscriberRegistry registry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     InboxConfiguration inboxConfiguration = null)
 {
     _asyncHandlerFactory = asyncHandlerFactory;
     _inboxConfiguration  = inboxConfiguration;
     _instanceScope       = new LifetimeScope(asyncHandlerFactory);
     _interpreter         = new Interpreter <TRequest>(registry, asyncHandlerFactory);
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when no task queue support is required and only async handlers are used
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IAmAPolicyRegistry policyRegistry)
 {
     _subscriberRegistry    = subscriberRegistry;
     _asyncHandlerFactory   = asyncHandlerFactory;
     _requestContextFactory = requestContextFactory;
     _policyRegistry        = policyRegistry;
 }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when no task queue support is required and only async handlers are used
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 /// <param name="featureSwitchRegistry">The feature switch config provider.</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IPolicyRegistry <string> policyRegistry,
     IAmAFeatureSwitchRegistry featureSwitchRegistry = null)
 {
     _subscriberRegistry    = subscriberRegistry;
     _asyncHandlerFactory   = asyncHandlerFactory;
     _requestContextFactory = requestContextFactory;
     _policyRegistry        = policyRegistry;
     _featureSwitchRegistry = featureSwitchRegistry;
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when both task queue and command processor support is required
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 /// <param name="mapperRegistry">The mapper registry.</param>
 /// <param name="asyncMessageStore">The message store supporting async/await.</param>
 /// <param name="asyncMessageProducer">The messaging gateway supporting async/await.</param>
 /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IAmAPolicyRegistry policyRegistry,
     IAmAMessageMapperRegistry mapperRegistry,
     IAmAMessageStoreAsync <Message> asyncMessageStore,
     IAmAMessageProducerAsync asyncMessageProducer,
     int messageStoreTimeout = 300
     )
     : this(
         subscriberRegistry, asyncHandlerFactory, requestContextFactory, policyRegistry, mapperRegistry,
         asyncMessageStore, asyncMessageProducer, LogProvider.For <CommandProcessor>(), messageStoreTimeout)
 {
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when both task queue and command processor support is required
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 /// <param name="mapperRegistry">The mapper registry.</param>
 /// <param name="asyncMessageStore">The message store supporting async/await.</param>
 /// <param name="asyncMessageProducer">The messaging gateway supporting async/await.</param>
 /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param>
 /// <param name="messageGatewaySendTimeout">How long should we wait to post to the message store</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IAmAPolicyRegistry policyRegistry,
     IAmAMessageMapperRegistry mapperRegistry,
     IAmAMessageStoreAsync <Message> asyncMessageStore,
     IAmAMessageProducerAsync asyncMessageProducer,
     int messageStoreTimeout       = 300,
     int messageGatewaySendTimeout = 300
     )
     : this(
         subscriberRegistry, asyncHandlerFactory, requestContextFactory, policyRegistry, mapperRegistry,
         asyncMessageStore, asyncMessageProducer, LogProvider.GetCurrentClassLogger())
 {
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when both task queue and command processor support is required
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 /// <param name="mapperRegistry">The mapper registry.</param>
 /// <param name="asyncMessageStore">The message store supporting async/await.</param>
 /// <param name="asyncMessageProducer">The messaging gateway supporting async/await.</param>
 /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IAmAPolicyRegistry policyRegistry,
     IAmAMessageMapperRegistry mapperRegistry,
     IAmAMessageStoreAsync <Message> asyncMessageStore,
     IAmAMessageProducerAsync asyncMessageProducer,
     int messageStoreTimeout = 300)
     : this(subscriberRegistry, asyncHandlerFactory, requestContextFactory, policyRegistry)
 {
     _mapperRegistry       = mapperRegistry;
     _asyncMessageStore    = asyncMessageStore;
     _asyncMessageProducer = asyncMessageProducer;
     _messageStoreTimeout  = messageStoreTimeout;
 }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when both task queue and command processor support is required
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 /// <param name="mapperRegistry">The mapper registry.</param>
 /// <param name="asyncMessageStore">The message store supporting async/await.</param>
 /// <param name="asyncMessageProducer">The messaging gateway supporting async/await.</param>
 /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param>
 /// <param name="featureSwitchRegistry">The feature switch config provider.</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IPolicyRegistry <string> policyRegistry,
     IAmAMessageMapperRegistry mapperRegistry,
     IAmAMessageStoreAsync <Message> asyncMessageStore,
     IAmAMessageProducerAsync asyncMessageProducer,
     int messageStoreTimeout = 300,
     IAmAFeatureSwitchRegistry featureSwitchRegistry = null)
     : this(subscriberRegistry, asyncHandlerFactory, requestContextFactory, policyRegistry, featureSwitchRegistry)
 {
     _mapperRegistry        = mapperRegistry;
     _asyncMessageStore     = asyncMessageStore;
     _asyncMessageProducer  = asyncMessageProducer;
     _messageStoreTimeout   = messageStoreTimeout;
     _featureSwitchRegistry = featureSwitchRegistry;
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when both task queue and command processor support is required
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 /// <param name="mapperRegistry">The mapper registry.</param>
 /// <param name="asyncOutbox">The outbox supporting async/await.</param>
 /// <param name="asyncMessageProducer">The messaging gateway supporting async/await.</param>
 /// <param name="outboxTimeout">How long should we wait to write to the outbox</param>
 /// <param name="featureSwitchRegistry">The feature switch config provider.</param>
 /// <param name="inboxConfiguration">Do we want to insert an inbox handler into pipelines without the attribute. Null (default = no), yes = how to configure</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactoryAsync asyncHandlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IPolicyRegistry <string> policyRegistry,
     IAmAMessageMapperRegistry mapperRegistry,
     IAmAnOutboxAsync <Message> asyncOutbox,
     IAmAMessageProducerAsync asyncMessageProducer,
     int outboxTimeout = 300,
     IAmAFeatureSwitchRegistry featureSwitchRegistry = null,
     InboxConfiguration inboxConfiguration           = null)
     : this(subscriberRegistry, asyncHandlerFactory, requestContextFactory, policyRegistry, featureSwitchRegistry)
 {
     _mapperRegistry        = mapperRegistry;
     _asyncOutbox           = asyncOutbox;
     _asyncMessageProducer  = asyncMessageProducer;
     _outboxTimeout         = outboxTimeout;
     _featureSwitchRegistry = featureSwitchRegistry;
     _inboxConfiguration    = inboxConfiguration;
 }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandProcessor"/> class.
 /// Use this constructor when no external bus is required and only sync handlers are needed
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="handlerFactory">The handler factory.</param>
 /// <param name="requestContextFactory">The request context factory.</param>
 /// <param name="policyRegistry">The policy registry.</param>
 /// <param name="featureSwitchRegistry">The feature switch config provider.</param>
 /// <param name="inboxConfiguration">Do we want to insert an inbox handler into pipelines without the attribute. Null (default = no), yes = how to configure</param>
 public CommandProcessor(
     IAmASubscriberRegistry subscriberRegistry,
     IAmAHandlerFactory handlerFactory,
     IAmARequestContextFactory requestContextFactory,
     IPolicyRegistry <string> policyRegistry,
     IAmAFeatureSwitchRegistry featureSwitchRegistry = null,
     InboxConfiguration inboxConfiguration           = null
     )
 {
     _subscriberRegistry = subscriberRegistry;
     if (handlerFactory is IAmAHandlerFactorySync handlerFactorySync)
     {
         _handlerFactorySync = handlerFactorySync;
     }
     if (handlerFactory is IAmAHandlerFactoryAsync handlerFactoryAsync)
     {
         _handlerFactoryAsync = handlerFactoryAsync;
     }
     _requestContextFactory = requestContextFactory;
     _policyRegistry        = policyRegistry;
     _featureSwitchRegistry = featureSwitchRegistry;
     _inboxConfiguration    = inboxConfiguration;
 }
예제 #15
0
 public LifetimeScope(IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory) 
 {
     _handlerFactory = handlerFactory;
     _asyncHandlerFactory = asyncHandlerFactory;
 }
예제 #16
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);
        }
예제 #17
0
 internal PipelineBuilder(IAmASubscriberRegistry registry, IAmAHandlerFactoryAsync asyncHandlerFactory)
     : this(registry, asyncHandlerFactory, LogProvider.For <PipelineBuilder <TRequest> >())
 {
 }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HandlerConfiguration"/> class.
 /// We use the <see cref="IAmASubscriberRegistry"/> instance to look up subscribers for messages when dispatching. Use <see cref="SubscriberRegistry"/> unless
 /// you have some reason to override. We expect a <see cref="CommandProcessor.Send{T}(T)"/> to have one registered handler
 /// We use the
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 public HandlerConfiguration(IAmASubscriberRegistry subscriberRegistry, IAmAHandlerFactoryAsync asyncHandlerFactory)
 {
     SubscriberRegistry  = subscriberRegistry;
     AsyncHandlerFactory = asyncHandlerFactory;
 }
예제 #19
0
 public LifetimeScope(IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory, ILog logger)
 {
     _handlerFactory      = handlerFactory;
     _asyncHandlerFactory = asyncHandlerFactory;
     _logger = logger;
 }
예제 #20
0
 public LifetimeScope(IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory)
     : this(handlerFactory, asyncHandlerFactory, LogProvider.For <LifetimeScope>())
 {
 }
예제 #21
0
 public LifetimeScope(IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory, ILog logger)
 {
     _handlerFactory = handlerFactory;
     _asyncHandlerFactory = asyncHandlerFactory;
     _logger = logger;
 }
예제 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HandlerConfiguration"/> class.
 /// We use the <see cref="IAmASubscriberRegistry"/> instance to look up subscribers for messages when dispatching. Use <see cref="SubscriberRegistry"/> unless
 /// you have some reason to override. We expect a <see cref="CommandProcessor.Send{T}(T)"/> to have one registered handler
 /// We use the 
 /// </summary>
 /// <param name="subscriberRegistry">The subscriber registry.</param>
 /// <param name="handlerFactory">The handler factory.</param>
 /// <param name="asyncHandlerFactory">The async handler factory.</param>
 public HandlerConfiguration(IAmASubscriberRegistry subscriberRegistry, IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory)
 {
     SubscriberRegistry = subscriberRegistry;
     HandlerFactory = handlerFactory;
     AsyncHandlerFactory = asyncHandlerFactory;
 }
예제 #23
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);
        }
예제 #24
0
 public LifetimeScope(IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory)
 {
     _handlerFactory      = handlerFactory;
     _asyncHandlerFactory = asyncHandlerFactory;
 }
예제 #25
0
 public LifetimeScope(IAmAHandlerFactoryAsync asyncHandlerFactory)
     : this(null, asyncHandlerFactory)
 {
 }
예제 #26
0
 internal PipelineBuilder(IAmASubscriberRegistry registry, IAmAHandlerFactoryAsync asyncHandlerFactory)
     : this(registry, asyncHandlerFactory, LogProvider.GetCurrentClassLogger())
 {
 }
예제 #27
0
 public LifetimeScope(IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory)
     : this(handlerFactory, asyncHandlerFactory, LogProvider.GetCurrentClassLogger())
 {
 }
예제 #28
0
 public LifetimeScope(IAmAHandlerFactoryAsync asyncHandlerFactory) 
     : this(null, asyncHandlerFactory)
 {}
예제 #29
0
 /// <summary>
 /// Supplies the specified handler configuration, so that we can register subscribers and the handler factory used to create instances of them
 /// </summary>
 /// <param name="handlerConfiguration">The handler configuration.</param>
 /// <returns>INeedPolicy.</returns>
 public INeedPolicy Handlers(HandlerConfiguration handlerConfiguration)
 {
     _registry = handlerConfiguration.SubscriberRegistry;
     _handlerFactory = handlerConfiguration.HandlerFactory;
     _asyncHandlerFactory = handlerConfiguration.AsyncHandlerFactory;
     return this;
 }
예제 #30
0
 internal Interpreter(IAmASubscriberRegistry registry, IAmAHandlerFactoryAsync asyncHandlerFactory)
     : this(registry, null, asyncHandlerFactory)
 {
 }
예제 #31
0
 public LifetimeScope(IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory) 
     :this(handlerFactory, asyncHandlerFactory, LogProvider.GetCurrentClassLogger())
 {}
예제 #32
0
 internal Interpreter(IAmASubscriberRegistry registry, IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory)
 {
     _registry            = registry;
     _handlerFactory      = handlerFactory;
     _asyncHandlerFactory = asyncHandlerFactory;
 }
예제 #33
0
 public LifetimeScope(IAmAHandlerFactorySync handlerFactorySync, IAmAHandlerFactoryAsync asyncHandlerFactory)
 {
     _handlerFactorySync  = handlerFactorySync;
     _asyncHandlerFactory = asyncHandlerFactory;
 }