protected virtual UnsubscribeAction Connect <TComponent, TMessage>(ISubscriberContext context)
            where TMessage : class
            where TComponent : class, Observes <TMessage, TComponent>, ISaga
        {
            MessageRouterConfigurator routerConfigurator = MessageRouterConfigurator.For(context.Pipeline);

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

            var instance = (Observes <TMessage, TComponent>) FastActivator <TComponent> .Create(Guid.Empty);

            Expression <Func <TComponent, TMessage, bool> > selector = instance.GetBindExpression();

            var repository = context.Builder.GetInstance <ISagaRepository <TComponent> >();
            var policy     = new ExistingSagaPolicy <TComponent, TMessage>(x => false);
            var sink       = new PropertySagaMessageSink <TComponent, TMessage>(context, context.Data as IServiceBus, repository, policy, selector);

            if (sink == null)
            {
                throw new ConfigurationException("Could not build the message sink for " + typeof(TComponent).FullName);
            }

            var result = router.Connect(sink);

            UnsubscribeAction remove = context.SubscribedTo <TMessage>();

            return(() => result() && (router.SinkCount == 0) && remove());
        }
        public BatchMessageRouter <TMessage, TBatchId> FindOrCreate <TMessage, TBatchId>()
            where TMessage : class, BatchedBy <TBatchId>
        {
            MessageRouterConfigurator configurator = MessageRouterConfigurator.For(_sink);

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

            var scope = new BatchMessageRouterConfiguratorScope <TMessage, TBatchId>();

            router.Inspect(scope);

            return(scope.Router ?? ConfigureRouter <TMessage, TBatchId>(router));
        }
Exemple #3
0
        protected virtual UnsubscribeAction Connect <TComponent, TMessage>(ISubscriberContext context)
            where TMessage : class, CorrelatedBy <Guid>
            where TComponent : class, Orchestrates <TMessage>, ISaga
        {
            MessageRouterConfigurator routerConfigurator = MessageRouterConfigurator.For(context.Pipeline);

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

            var repository = context.Builder.GetInstance <ISagaRepository <TComponent> >();
            var policy     = new ExistingSagaPolicy <TComponent, TMessage>(x => false);
            var sink       = new CorrelatedSagaMessageSink <TComponent, TMessage>(context, context.Data as IServiceBus, repository, policy);

            if (sink == null)
            {
                throw new ConfigurationException("Could not build the message sink for " + typeof(TComponent).FullName);
            }

            var result = router.Connect(sink);

            UnsubscribeAction remove = context.SubscribedTo <TMessage>();

            return(() => result() && (router.SinkCount == 0) && remove());
        }