Esempio n. 1
0
        public void Publish <T>(T @event) where T : class, IRequest
        {
            var builder        = new ChainofResponsibilityBuilder <T>(container);
            var requestContext = new RequestContext();
            var handlerChain   = builder.Build(requestContext);

            handlerChain.Each(chain => chain.Handle(@event));
        }
Esempio n. 2
0
        public void Send <T>(T command) where T : class, IRequest
        {
            var builder        = new ChainofResponsibilityBuilder <T>(container);
            var requestContext = requestContextFactory.Create();
            var handlerChain   = builder.Build(requestContext);

            var handlerCount = handlerChain.Count();

            if (handlerCount > 1)
            {
                throw new ArgumentException(string.Format("More than one handler was found for the typeof command {0} - a command should only have one handler.", typeof(T)));
            }
            if (handlerCount == 0)
            {
                throw new ArgumentException(string.Format("No command handler was found for the typeof command {0} - a command should have only one handler.", typeof(T)));
            }

            handlerChain.First().Handle(command);
        }