Пример #1
0
        /// <summary>
        /// Add an exchange as a singleton.
        /// </summary>
        /// <param name="services">Service collection.</param>
        /// <param name="exchangeName">Exchange name.</param>
        /// <param name="options">Exchange configuration <see cref="RabbitMqExchangeOptions"/>.</param>
        /// <param name="clientExchangeType">Custom client exchange type that defines what functionality is allowed for an exchange.</param>
        /// <returns>Service collection.</returns>
        public static IServiceCollection AddExchange(this IServiceCollection services, string exchangeName, RabbitMqExchangeOptions?options, ClientExchangeType clientExchangeType = ClientExchangeType.Universal)
        {
            var exchangeOptions = options ?? new RabbitMqExchangeOptions();

            ValidateExchangeTypes(exchangeName, exchangeOptions);
            EnsureExchangeHasNotBeenConfiguredYet(services, exchangeName, clientExchangeType);

            var exchange = new RabbitMqExchange(exchangeName, clientExchangeType, exchangeOptions);
            var service  = new ExchangeServiceDescriptor(typeof(RabbitMqExchange), exchange, exchangeName, clientExchangeType);

            services.Add(service);
            return(services);
        }
Пример #2
0
        /// <summary>
        /// Add exchange as singleton.
        /// </summary>
        /// <param name="services">Service collection.</param>
        /// <param name="exchangeName">Exchange name.</param>
        /// <param name="options">Exchange configuration <see cref="RabbitMqExchangeOptions"/>.</param>
        /// <returns>Service collection.</returns>
        public static IServiceCollection AddExchange(this IServiceCollection services, string exchangeName, RabbitMqExchangeOptions options)
        {
            CheckExchangeExists(services, exchangeName);

            var exchangeOptions = options ?? new RabbitMqExchangeOptions();
            var exchange        = new RabbitMqExchange {
                Name = exchangeName, Options = exchangeOptions
            };
            var service = new ExchangeServiceDescriptor(typeof(RabbitMqExchange), exchange)
            {
                ExchangeName = exchangeName
            };

            services.Add(service);
            return(services);
        }