@@ -35,7 +35,7 @@ public Startup(IConfiguration configuration)
3535 Configuration = configuration ;
3636 }
3737
38- public IConfiguration Configuration { get ; }
38+ public IConfiguration Configuration { get ; }
3939
4040 public IServiceProvider ConfigureServices ( IServiceCollection services )
4141 {
@@ -161,7 +161,13 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
161161 factory . Password = Configuration [ "EventBusPassword" ] ;
162162 }
163163
164- return new DefaultRabbitMQPersistentConnection ( factory , logger ) ;
164+ var retryCount = 5 ;
165+ if ( ! string . IsNullOrEmpty ( Configuration [ "EventBusRetryCount" ] ) )
166+ {
167+ retryCount = int . Parse ( Configuration [ "EventBusRetryCount" ] ) ;
168+ }
169+
170+ return new DefaultRabbitMQPersistentConnection ( factory , logger , retryCount ) ;
165171 } ) ;
166172 }
167173
@@ -188,7 +194,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
188194 loggerFactory . CreateLogger ( "init" ) . LogDebug ( $ "Using PATH BASE '{ pathBase } '") ;
189195 app . UsePathBase ( pathBase ) ;
190196 }
191-
197+
192198 app . UseCors ( "CorsPolicy" ) ;
193199
194200 app . UseMvcWithDefaultRoute ( ) ;
@@ -221,7 +227,21 @@ private void RegisterEventBus(IServiceCollection services)
221227 }
222228 else
223229 {
224- services . AddSingleton < IEventBus , EventBusRabbitMQ > ( ) ;
230+ services . AddSingleton < IEventBus , EventBusRabbitMQ > ( sp =>
231+ {
232+ var rabbitMQPersistentConnection = sp . GetRequiredService < IRabbitMQPersistentConnection > ( ) ;
233+ var iLifetimeScope = sp . GetRequiredService < ILifetimeScope > ( ) ;
234+ var logger = sp . GetRequiredService < ILogger < EventBusRabbitMQ > > ( ) ;
235+ var eventBusSubcriptionsManager = sp . GetRequiredService < IEventBusSubscriptionsManager > ( ) ;
236+
237+ var retryCount = 5 ;
238+ if ( ! string . IsNullOrEmpty ( Configuration [ "EventBusRetryCount" ] ) )
239+ {
240+ retryCount = int . Parse ( Configuration [ "EventBusRetryCount" ] ) ;
241+ }
242+
243+ return new EventBusRabbitMQ ( rabbitMQPersistentConnection , logger , iLifetimeScope , eventBusSubcriptionsManager , retryCount ) ;
244+ } ) ;
225245 }
226246
227247 services . AddSingleton < IEventBusSubscriptionsManager , InMemoryEventBusSubscriptionsManager > ( ) ;
0 commit comments