Пример #1
0
        public static UnsubscribeAction ConnectToRouter <T>(this IMessagePipeline pipeline, IPipelineSink <T> sink)
            where T : class
        {
            MessageRouterConfigurator routerConfigurator = MessageRouterConfigurator.For(pipeline);

            MessageRouter <T> router = routerConfigurator.FindOrCreate <T>();

            UnsubscribeAction result = router.Connect(sink);

            return(() => result() && (router.SinkCount == 0));
        }
Пример #2
0
        public CorrelatedMessageRouter <TMessage, TKey> FindOrCreate <TMessage, TKey>()
            where TMessage : class, CorrelatedBy <TKey>
        {
            MessageRouterConfigurator configurator = MessageRouterConfigurator.For(_sink);

            MessageRouter <TMessage> router = configurator.FindOrCreate <TMessage>();

            var scope = new CorrelatedMessageRouterConfiguratorScope <TMessage, TKey>();

            router.Inspect(scope);

            return(scope.Router ?? ConfigureRouter <TMessage, TKey>(router));
        }
Пример #3
0
        public UnsubscribeAction Subscribe <TMessage>(Func <TMessage, Action <TMessage> > getHandler) where TMessage : class
        {
            var routerConfigurator = MessageRouterConfigurator.For(_pipeline);

            var router = routerConfigurator.FindOrCreate <TMessage>();

            Func <TMessage, Action <TMessage> > consumer = getHandler;

            var sink = new InstanceMessageSink <TMessage>(consumer);

            var result = router.Connect(sink);

            UnsubscribeAction remove = SubscribedTo <TMessage>();

            return(() => result() && (router.SinkCount == 0) && remove());
        }
        private static void EnsureRouterExists <TMessage>(IPipelineSink <object> sink) where TMessage : class
        {
            MessageRouterConfigurator routerConfigurator = MessageRouterConfigurator.For(sink);

            routerConfigurator.FindOrCreate <TMessage>();
        }