/// <summary>
 /// Add a singleton producing RabbitMQ service <see cref="IProducingService"/> and required infrastructure.
 /// </summary>
 /// <param name="services">Service collection.</param>
 /// <param name="configuration">RabbitMq configuration section.</param>
 /// <returns>Service collection.</returns>
 public static IServiceCollection AddRabbitMqProducer(this IServiceCollection services, IConfiguration configuration)
 {
     services.AddRabbitMqInfrastructure();
     services.ConfigureRabbitMqProducingOnlyServiceOptions(RabbitMqServiceOptionsDependencyInjectionExtensions.GetRabbitMqServiceOptionsInstance(configuration));
     services.AddRabbitMqServices();
     return(services);
 }
 /// <summary>
 /// Add fully-functional RabbitMQ services and required infrastructure.
 /// RabbitMQ services consists of two components: consumer <see cref="IConsumingService"/> and producer <see cref="IProducingService"/>.
 /// </summary>
 /// <param name="services">Service collection.</param>
 /// <param name="configuration">RabbitMq configuration section.</param>
 /// <returns>Service collection.</returns>
 public static IServiceCollection AddRabbitMqServices(this IServiceCollection services, IConfiguration configuration)
 {
     services.AddRabbitMqInfrastructure();
     services.ConfigureRabbitMqConnectionOptions(RabbitMqServiceOptionsDependencyInjectionExtensions.GetRabbitMqServiceOptionsInstance(configuration));
     services.AddRabbitMqServices();
     services.AddConsumptionStarter();
     return(services);
 }
Пример #3
0
        /// <summary>
        /// Add batch message handler.
        /// </summary>
        /// <typeparam name="TBatchMessageHandler">Batch message handler type.</typeparam>
        /// <param name="services">Service collection.</param>
        /// <param name="configuration">RabbitMq configuration section.</param>
        /// <returns>Service collection.</returns>
        public static IServiceCollection AddBatchMessageHandler <TBatchMessageHandler>(this IServiceCollection services, IConfiguration configuration)
            where TBatchMessageHandler : BaseBatchMessageHandler
        {
            CheckIfBatchMessageHandlerAlreadyConfigured <TBatchMessageHandler>(services);
            services.TryAddSingleton <IRabbitMqConnectionFactory, RabbitMqConnectionFactory>();
            var configurationInstance = RabbitMqServiceOptionsDependencyInjectionExtensions.GetRabbitMqServiceOptionsInstance(configuration);

            services.ConfigureBatchConsumerConnectionOptions <TBatchMessageHandler>(configurationInstance);
            services.AddHostedService <TBatchMessageHandler>();
            return(services);
        }