コード例 #1
0
        public void Test()
        {
            var down1 = new ForwardingDownHandler();
            var down2 = new ForwardingDownHandler();
            var up1 = new ForwardingUpHandler();
            var up2 = new ForwardingUpHandler();
            var handler = Substitute.For<IUpstreamHandler>();

            var bp = new PipelineBuilder();
            bp.RegisterDownstream(down1);
            bp.RegisterDownstream(down2);
            bp.RegisterUpstream(up1);
            bp.RegisterUpstream(up2);
            bp.RegisterUpstream(handler);
            var pipeline = bp.Build();

            pipeline.Start();
            pipeline.Send(new DispatchEvent(new FakeEvent()));

            foreach (var call in handler.ReceivedCalls())
            {
                Console.WriteLine(call.GetArguments()[1]);
            }
        }
コード例 #2
0
        /// <summary>
        /// Build the pipeline
        /// </summary>
        /// <returns>Constructed pipeline</returns>
        public IDomainEventDispatcher Build()
        {
            if (_inner == null)
                throw new InvalidOperationException(
                    "You must specify a dispatcher, either through the UseContainer() method or by the UseCustomDispatcher() method.");

            var builder = new PipelineBuilder();
            if (_unitOfWorkAdapter != null)
                builder.RegisterDownstream(new TransactionalHandler(_unitOfWorkAdapter, _storage));

            if (_maxWorkers > 0)
                builder.RegisterDownstream(new AsyncHandler(_maxWorkers));

            builder.RegisterDownstream(_inner);

            builder.RegisterUpstream(_errorHandler);
            var pipeline = builder.Build();
            pipeline.Start();
            return new EventPipelineDispatcher(pipeline);
        }
コード例 #3
0
        /// <summary>
        /// Build the dispatcher.
        /// </summary>
        /// <returns>Created dispatcher</returns>
        public ICommandDispatcher Build()
        {
            if (_lastHandler == null && _container == null)
                throw new InvalidOperationException(
                    "You must have specified a handler which can actually invoke the correct command handler. For instance the 'IocDispatcher'.");
            if (_container == null && _lastHandler == null)
                throw new InvalidOperationException(
                    "You must have specified a SINGLE handler that can invoke the correct command handler. Either use 'IocDispatcher' or another one, not both alternatives.");

            var builder = new PipelineBuilder();

            // must be registered before the storage since the storage listens on CommandAborted
            if (_maxAttempts > 0)
            {
                var handler = new RetryingHandler(_maxAttempts);
                builder.RegisterUpstream(handler);
            }

            // Must be registered before the async handler.
            if (_storageHandler != null)
            {
                builder.RegisterDownstream(_storageHandler);
                builder.RegisterUpstream(_storageHandler);
            }


            if (_workers > 0)
                builder.RegisterDownstream(new AsyncHandler(_workers));

            if (_container != null)
                builder.RegisterDownstream(new Pipeline.IocDispatcher(_container));
            else
                builder.RegisterDownstream(_lastHandler);

            builder.RegisterUpstream(_errorHandler);
            var pipeline = builder.Build();
            pipeline.Start();
            var dispatcher = new PipelineDispatcher(pipeline);
            return dispatcher;
        }