1
1
using System . Linq ;
2
2
using Microsoft . Extensions . Configuration ;
3
3
using Microsoft . Extensions . DependencyInjection ;
4
+ using Microsoft . Extensions . DependencyInjection . Extensions ;
4
5
using RabbitMQ . Client . Core . DependencyInjection . BatchMessageHandlers ;
5
6
using RabbitMQ . Client . Core . DependencyInjection . Configuration ;
6
7
using RabbitMQ . Client . Core . DependencyInjection . Exceptions ;
7
8
using RabbitMQ . Client . Core . DependencyInjection . InternalExtensions ;
8
9
using RabbitMQ . Client . Core . DependencyInjection . Models ;
10
+ using RabbitMQ . Client . Core . DependencyInjection . Services ;
9
11
10
12
namespace RabbitMQ . Client . Core . DependencyInjection
11
13
{
@@ -25,6 +27,7 @@ public static IServiceCollection AddBatchMessageHandler<TBatchMessageHandler>(th
25
27
where TBatchMessageHandler : BaseBatchMessageHandler
26
28
{
27
29
CheckIfBatchMessageHandlerAlreadyConfigured < TBatchMessageHandler > ( services ) ;
30
+ services . TryAddSingleton < IRabbitMqConnectionFactory , RabbitMqConnectionFactory > ( ) ;
28
31
var configurationInstance = RabbitMqClientOptionsDependencyInjectionExtensions . GetRabbitMqClientOptionsInstance ( configuration ) ;
29
32
services . ConfigureBatchConsumerConnectionOptions < TBatchMessageHandler > ( configurationInstance ) ;
30
33
services . AddHostedService < TBatchMessageHandler > ( ) ;
@@ -42,6 +45,7 @@ public static IServiceCollection AddBatchMessageHandler<TBatchMessageHandler>(th
42
45
where TBatchMessageHandler : BaseBatchMessageHandler
43
46
{
44
47
CheckIfBatchMessageHandlerAlreadyConfigured < TBatchMessageHandler > ( services ) ;
48
+ services . TryAddSingleton < IRabbitMqConnectionFactory , RabbitMqConnectionFactory > ( ) ;
45
49
services . ConfigureBatchConsumerConnectionOptions < TBatchMessageHandler > ( configuration ) ;
46
50
services . AddHostedService < TBatchMessageHandler > ( ) ;
47
51
return services ;
0 commit comments