コード例 #1
0
        public void Invoke(BehaviorContext context, Action next)
        {
            // for now we cheat and pull it from the behavior context:
            var callbackInvoked = context.Get<bool>(CallbackInvocationBehavior.CallbackInvokedKey);
            var messageHandlers = new LoadedMessageHandlers();

            foreach (var messageToHandle in context.Get<LogicalMessages>())
            {
                var handlerTypedToInvoke = HandlerRegistry.GetHandlerTypes(messageToHandle.MessageType).ToList();

                if (!callbackInvoked && !handlerTypedToInvoke.Any())
                {
                    var error = string.Format("No handlers could be found for message type: {0}", messageToHandle.MessageType);
                    throw new InvalidOperationException(error);
                }

                foreach (var handlerType in handlerTypedToInvoke)
                {
                    messageHandlers.AddHandler(messageToHandle.MessageType, context.Builder.Build(handlerType));
                }
            }

            context.Set(messageHandlers);

            next();
        }
コード例 #2
0
        public void Invoke(BehaviorContext context, Action next)
        {
            // for now we cheat and pull it from the behavior context:
            var callbackInvoked = context.Get <bool>(CallbackInvocationBehavior.CallbackInvokedKey);
            var messageHandlers = new LoadedMessageHandlers();

            foreach (var messageToHandle in context.Get <LogicalMessages>())
            {
                var handlerTypedToInvoke = HandlerRegistry.GetHandlerTypes(messageToHandle.MessageType).ToList();

                if (!callbackInvoked && !handlerTypedToInvoke.Any())
                {
                    var error = string.Format("No handlers could be found for message type: {0}", messageToHandle.MessageType);
                    throw new InvalidOperationException(error);
                }

                foreach (var handlerType in handlerTypedToInvoke)
                {
                    messageHandlers.AddHandler(messageToHandle.MessageType, context.Builder.Build(handlerType));
                }
            }

            context.Set(messageHandlers);

            next();
        }