Пример #1
0
        /// <summary>
        /// Registers a message handler if one doesn't exist for the given message type, otherwise
        /// overwrites the previously registered handler for that message type.
        /// </summary>
        /// <param name="messageType">The message type to set the handler for.</param>
        /// <param name="messageHandler">The message handler.</param>
        /// <returns></returns>
        public MessageHandlerCollectionBuilder SetHandler(string messageType, HandlerAsyncDelegate messageHandler)
        {
            if (messageType == null)
            {
                throw new ArgumentNullException(nameof(messageType));
            }

            this.MessageHandlerCollection[messageType] = messageHandler ?? throw new ArgumentNullException(nameof(messageHandler));

            return(this);
        }
Пример #2
0
        /// <summary>
        /// Sets the default handler to use when a message has a type which has no registered handlers.
        /// </summary>
        /// <param name="messageHandler">The default handler implementation.</param>
        public MessageHandlerCollectionBuilder SetDefaultHandler(HandlerAsyncDelegate messageHandler)
        {
            this.MessageHandlerCollection.FallbackMessageHandler = messageHandler ?? throw new ArgumentNullException(nameof(messageHandler));

            return(this);
        }