/// <summary>
        /// Subscribe a component type to the pipeline that is resolved from the container for each message
        /// </summary>
        /// <typeparam name="TComponent"></typeparam>
        /// <param name="pipeline">The pipeline to configure</param>
        /// <returns></returns>
        public static UnsubscribeAction ConnectConsumer <TComponent>(this IInboundMessagePipeline pipeline)
            where TComponent : class, new()
        {
            return(pipeline.Configure(x =>
            {
                var consumerFactory = new DelegateConsumerFactory <TComponent>(() => new TComponent());

                ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TComponent>();
                return connector.Connect(x, consumerFactory);
            }));
        }
        /// <summary>
        /// Subscribe a component type to the pipeline that is resolved from the container for each message
        /// </summary>
        /// <typeparam name="TConsumer"></typeparam>
        /// <param name="pipeline">The pipeline to configure</param>
        /// <param name="consumerFactory"></param>
        /// <returns></returns>
        public static UnsubscribeAction ConnectConsumer <TConsumer>(this IInboundMessagePipeline pipeline,
                                                                    Func <TConsumer> consumerFactory)
            where TConsumer : class
        {
            return(pipeline.Configure(x =>
            {
                var factory = new DelegateConsumerFactory <TConsumer>(consumerFactory);

                ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();
                return connector.Connect(x, factory);
            }));
        }
        public static UnsubscribeAction SubscribeConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                      [NotNull] IConsumerFactory <TConsumer>
                                                                      consumerFactory)
            where TConsumer : class
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using supplied consumer factory)", typeof(TConsumer));
            }

            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, consumerFactory)));
        }
        public static UnsubscribeAction SubscribeConsumer <TConsumer>([NotNull] this IServiceBus bus)
            where TConsumer : class, new()
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using default consumer factory)", typeof(TConsumer));
            }

            var delegateConsumerFactory = new DelegateConsumerFactory <TConsumer>(() => new TConsumer());

            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, delegateConsumerFactory)));
        }
        public static UnsubscribeAction SubscribeInterceptingConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                                  [NotNull] Func <TConsumer> consumerFactory, [NotNull] Action <Action> interceptor)
            where TConsumer : class, IConsumer
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using delegate consumer factory)", typeof(TConsumer));
            }

            var delegateConsumerFactory = new DelegateConsumerFactory <TConsumer>(consumerFactory);

            var interceptingConsumerFactory = new InterceptingConsumerFactory <TConsumer>(delegateConsumerFactory,
                                                                                          interceptor);
            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, interceptingConsumerFactory)));
        }
        public ISubscriptionReference Subscribe(IInboundPipelineConfigurator configurator)
        {
            UnsubscribeAction unsubscribe = _consumerConnector.Connect(configurator, _consumerFactory);

            return(_referenceFactory(unsubscribe));
        }