/// <summary>
        /// Connects any consumers for the component to the message dispatcher
        /// </summary>
        /// <param name="bus">The service bus to configure</param>
        /// <param name="instance"></param>
        /// <returns>The unsubscribe action that can be called to unsubscribe the instance
        /// passed as an argument.</returns>
        public static UnsubscribeAction SubscribeInstance([NotNull] this IServiceBus bus, [NotNull] object instance)
        {
            Guard.AgainstNull(instance, "instance", "A null instance cannot be subscribed");

            IInstanceConnector connector = InstanceConnectorCache.GetInstanceConnector(instance.GetType());

            return(bus.Configure(x => connector.Connect(x, instance)));
        }
        /// <summary>
        /// Connects any consumers for the component to the message dispatcher
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <param name="bus">The service bus instance to call this method on.</param>
        /// <param name="instance">The instance to subscribe.</param>
        /// <returns>The unsubscribe action that can be called to unsubscribe the instance
        /// passed as an argument.</returns>
        public static UnsubscribeAction SubscribeInstance <T>([NotNull] this IServiceBus bus, [NotNull] T instance)
            where T : class, IConsumer
        {
            Guard.AgainstNull(instance, "instance", "A null instance cannot be subscribed");

            IInstanceConnector connector = InstanceConnectorCache.GetInstanceConnector <T>();

            return(bus.Configure(x => connector.Connect(x, instance)));
        }
 /// <summary>
 /// Subscribe a component to the pipeline that handles every message
 /// </summary>
 /// <typeparam name="TComponent"></typeparam>
 /// <param name="pipeline">The pipeline to configure</param>
 /// <param name="instance">The instance that will handle the messages</param>
 /// <returns></returns>
 public static UnsubscribeAction ConnectInstance <TComponent>(this IInboundMessagePipeline pipeline, TComponent instance)
     where TComponent : class
 {
     return(pipeline.Configure(x =>
     {
         IInstanceConnector connector = InstanceConnectorCache.GetInstanceConnector <TComponent>();
         return connector.Connect(x, instance);
     }));
 }
示例#4
0
        public ISubscriptionReference Subscribe(IInboundPipelineConfigurator configurator)
        {
            UnsubscribeAction unsubscribe = _connector.Connect(configurator, _instance);

            return(_referenceFactory(unsubscribe));
        }