@@ -88,7 +88,7 @@ protected virtual void ConfigureEventBus(IApplicationBuilder app)
8888 }
8989}
9090
91- static class CustomExtensionMethods
91+ internal static class CustomExtensionMethods
9292{
9393 public static IServiceCollection AddAppInsight ( this IServiceCollection services , IConfiguration configuration )
9494 {
@@ -171,53 +171,50 @@ public static IServiceCollection AddSwagger(this IServiceCollection services, IC
171171 public static IServiceCollection AddEventBus ( this IServiceCollection services , IConfiguration configuration )
172172 {
173173 if ( configuration . GetValue < bool > ( "AzureServiceBusEnabled" ) )
174+ {
175+ services . AddSingleton < IEventBus , EventBusServiceBus > ( sp =>
174176 {
175- services . AddSingleton < IEventBus , EventBusServiceBus > ( sp =>
176- {
177- var serviceBusPersisterConnection = sp . GetRequiredService < IServiceBusPersisterConnection > ( ) ;
178- var iLifetimeScope = sp . GetRequiredService < ILifetimeScope > ( ) ;
179- var logger = sp . GetRequiredService < ILogger < EventBusServiceBus > > ( ) ;
180- var eventBusSubcriptionsManager = sp . GetRequiredService < IEventBusSubscriptionsManager > ( ) ;
181- string subscriptionName = configuration [ "SubscriptionClientName" ] ;
182-
183- return new EventBusServiceBus ( serviceBusPersisterConnection , logger ,
184- eventBusSubcriptionsManager , iLifetimeScope , subscriptionName ) ;
185- } ) ;
177+ var serviceBusPersisterConnection = sp . GetRequiredService < IServiceBusPersisterConnection > ( ) ;
178+ var iLifetimeScope = sp . GetRequiredService < ILifetimeScope > ( ) ;
179+ var logger = sp . GetRequiredService < ILogger < EventBusServiceBus > > ( ) ;
180+ var eventBusSubscriptionManager = sp . GetRequiredService < IEventBusSubscriptionsManager > ( ) ;
181+ string subscriptionName = configuration [ "SubscriptionClientName" ] ;
182+
183+ return new EventBusServiceBus ( serviceBusPersisterConnection , logger ,
184+ eventBusSubscriptionManager , iLifetimeScope , subscriptionName ) ;
185+ } ) ;
186186
187- }
188- else
187+ }
188+ else
189+ {
190+ services . AddSingleton < IEventBus , EventBusRabbitMQ > ( sp =>
189191 {
190- services . AddSingleton < IEventBus , EventBusRabbitMQ > ( sp =>
192+ var subscriptionClientName = configuration [ "SubscriptionClientName" ] ;
193+ var rabbitMQPersistentConnection = sp . GetRequiredService < IRabbitMQPersistentConnection > ( ) ;
194+ var iLifetimeScope = sp . GetRequiredService < ILifetimeScope > ( ) ;
195+ var logger = sp . GetRequiredService < ILogger < EventBusRabbitMQ > > ( ) ;
196+ var eventBusSubscriptionManager = sp . GetRequiredService < IEventBusSubscriptionsManager > ( ) ;
197+
198+ var retryCount = 5 ;
199+ if ( ! string . IsNullOrEmpty ( configuration [ "EventBusRetryCount" ] ) )
191200 {
192- var subscriptionClientName = configuration [ "SubscriptionClientName" ] ;
193- var rabbitMQPersistentConnection = sp . GetRequiredService < IRabbitMQPersistentConnection > ( ) ;
194- var iLifetimeScope = sp . GetRequiredService < ILifetimeScope > ( ) ;
195- var logger = sp . GetRequiredService < ILogger < EventBusRabbitMQ > > ( ) ;
196- var eventBusSubcriptionsManager = sp . GetRequiredService < IEventBusSubscriptionsManager > ( ) ;
197-
198- var retryCount = 5 ;
199- if ( ! string . IsNullOrEmpty ( configuration [ "EventBusRetryCount" ] ) )
200- {
201- retryCount = int . Parse ( configuration [ "EventBusRetryCount" ] ) ;
202- }
201+ retryCount = int . Parse ( configuration [ "EventBusRetryCount" ] ) ;
202+ }
203203
204- return new EventBusRabbitMQ ( rabbitMQPersistentConnection , logger , iLifetimeScope , eventBusSubcriptionsManager , subscriptionClientName , retryCount ) ;
205- } ) ;
206- }
204+ return new EventBusRabbitMQ ( rabbitMQPersistentConnection , logger , iLifetimeScope , eventBusSubscriptionManager , subscriptionClientName , retryCount ) ;
205+ } ) ;
206+ }
207207
208- services . AddSingleton < IEventBusSubscriptionsManager , InMemoryEventBusSubscriptionsManager > ( ) ;
209- services . AddTransient < ProductPriceChangedIntegrationEventHandler > ( ) ;
210- services . AddTransient < OrderStatusChangedToShippedIntegrationEventHandler > ( ) ;
211- services . AddTransient < OrderStatusChangedToPaidIntegrationEventHandler > ( ) ;
208+ services . AddSingleton < IEventBusSubscriptionsManager , InMemoryEventBusSubscriptionsManager > ( ) ;
209+ services . AddTransient < ProductPriceChangedIntegrationEventHandler > ( ) ;
210+ services . AddTransient < OrderStatusChangedToShippedIntegrationEventHandler > ( ) ;
211+ services . AddTransient < OrderStatusChangedToPaidIntegrationEventHandler > ( ) ;
212212
213- return services ;
213+ return services ;
214214 }
215215
216216 public static IServiceCollection AddCustomHealthCheck ( this IServiceCollection services , IConfiguration configuration )
217217 {
218- var accountName = configuration . GetValue < string > ( "AzureStorageAccountName" ) ;
219- var accountKey = configuration . GetValue < string > ( "AzureStorageAccountKey" ) ;
220-
221218 var hcBuilder = services . AddHealthChecks ( ) ;
222219
223220 hcBuilder
0 commit comments