Пример #1
0
        public void DispatchTest()
        {
            var ddWrite    = new DynamicDispatch <Writer, Node>("Write");
            var ddMulWrite = new DynamicDispatch <MultiplyWriter, Node>("Write");

            var tree = new BinaryNode
            {
                Left = new BinaryNode
                {
                    Left  = new ValueNode(3),
                    Right = new BinaryNode {
                        Left  = new ValueNode(4),
                        Right = new ValueNode(6)
                    }
                },
                Right = new ValueNode(8)
            };

            var sw = new StringWriter();

            ddWrite.Dispatch(new Writer(sw), tree);
            Assert.AreEqual("3,4,6,8", sw.ToString());

            sw = new StringWriter();
            ddMulWrite.Dispatch(new MultiplyWriter(sw, 2), tree);
            Assert.AreEqual("6,8,12,16", sw.ToString());
        }
Пример #2
0
        public async Task <Message> Process(Message message)
        {
            var request  = message?.Payload;
            var response = await DynamicDispatch.Dispatch(_mediator, request, _ =>
            {
                throw new HttpResponseException(HttpStatusCodeExtensions.UnprocessableEntity);
            });

            return(response is Unit ? new Message() : new Message(response));
        }
Пример #3
0
 private Task <object> Process(object request)
 {
     using (_mediator.NewScope())
         return(DynamicDispatch.Dispatch(_mediator, request));
 }
 public Task <object> Route(Routed route, object message, IMediator mediator)
 {
     return(DynamicDispatch.Dispatch(mediator, message));
 }