コード例 #1
0
        public TResult Request <TMsg, TResult>(TMsg args) where TMsg : IRequest
        {
            var handlers = GetHandlers <TMsg>();

            MessageBusCheck.Require(handlers != null && handlers.Any(), "No handlers found for message type " + args.GetType().Name);
            MessageBusCheck.Require(handlers.Count() == 1, "Expected exactly one handler for request " + args.GetType().Name + ". Found " + handlers.Count() + " handlers.");
            return((TResult)Invoke("Get", handlers.First(), args));
        }
コード例 #2
0
        public void Send <TMsg>(TMsg args) where TMsg : ICommand
        {
            var handlers = GetHandlers <TMsg>();

            MessageBusCheck.Require(handlers != null && handlers.Any(), "No handlers found for message type " + args.GetType().Name);
            foreach (var handler in handlers)
            {
                Invoke("Handle", handler, args);
            }
        }
コード例 #3
0
        public TResult Create <TMsg, TResult>(TMsg args) where TMsg : ICommand
        {
            var handlers = GetHandlers <TMsg>();

            MessageBusCheck.Require(handlers != null && handlers.Any(), "No handlers found for message type " + typeof(TMsg).Name);
            object result = null;

            foreach (var handler in handlers)
            {
                object newResult = Invoke("Handle", handler, args);
                MessageBusCheck.Require(newResult == null || result == null, "Only one handler for a Create message can return a value, found multiple return objects for message {0}.", args.GetType().Name);
                if (newResult != null)
                {
                    result = newResult;
                }
            }
            return((TResult)result);
        }