示例#1
0
        /// <summary>
        /// Adds support for the specified message type.
        /// </summary>
        /// <typeparam name="TMessage">
        /// The type of the message for which support is added.
        /// </typeparam>
        /// <param name="entityType">
        /// The targeted entity type.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// <typeparamref name="TMessage" /> was already added.
        /// </exception>
        public void AddSubscriber <TMessage>(MessagingEntityType entityType)
            where TMessage : class, IMessage
        {
            var messageType = typeof(TMessage);

            if (SupportedMessageTypesReference.Contains(messageType))
            {
                throw new InvalidOperationException($"Support for the type {messageType.FullName} was already added.");
            }

            SupportedMessageTypesReference.Add(messageType);
            RootDependencyScope.Resolve <IMessageSubscriptionClient>().RegisterHandler <TMessage>((message) => HandleMessage(message), entityType);
        }
示例#2
0
        /// <summary>
        /// Adds support for the specified request message type.
        /// </summary>
        /// <typeparam name="TRequestMessage">
        /// The type of the request message for which support is added.
        /// </typeparam>
        /// <typeparam name="TResponseMessage">
        /// The type of the response message that is associated with <typeparamref name="TRequestMessage" />.
        /// </typeparam>
        /// <exception cref="InvalidOperationException">
        /// <typeparamref name="TRequestMessage" /> was already added.
        /// </exception>
        public void AddRequestSubscriber <TRequestMessage, TResponseMessage>()
            where TRequestMessage : class, IRequestMessage <TResponseMessage>
            where TResponseMessage : class, IResponseMessage
        {
            var requestMessageType = typeof(TRequestMessage);

            if (SupportedMessageTypesReference.Contains(requestMessageType))
            {
                throw new InvalidOperationException($"Support for the type {requestMessageType.FullName} was already added.");
            }

            SupportedMessageTypesReference.Add(requestMessageType);
            RootDependencyScope.Resolve <IMessageSubscriptionClient>().RegisterHandler <TRequestMessage, TResponseMessage>((requestMessage) => HandleRequestMessage <TRequestMessage, TResponseMessage>(requestMessage));
        }