|
|
@ -88,7 +88,7 @@ public class Startup |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static class CustomExtensionMethods |
|
|
|
internal static class CustomExtensionMethods |
|
|
|
{ |
|
|
|
public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration) |
|
|
|
{ |
|
|
@ -171,53 +171,50 @@ static class CustomExtensionMethods |
|
|
|
public static IServiceCollection AddEventBus(this IServiceCollection services, IConfiguration configuration) |
|
|
|
{ |
|
|
|
if (configuration.GetValue<bool>("AzureServiceBusEnabled")) |
|
|
|
{ |
|
|
|
services.AddSingleton<IEventBus, EventBusServiceBus>(sp => |
|
|
|
{ |
|
|
|
services.AddSingleton<IEventBus, EventBusServiceBus>(sp => |
|
|
|
{ |
|
|
|
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>(); |
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); |
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>(); |
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |
|
|
|
string subscriptionName = configuration["SubscriptionClientName"]; |
|
|
|
|
|
|
|
return new EventBusServiceBus(serviceBusPersisterConnection, logger, |
|
|
|
eventBusSubcriptionsManager, iLifetimeScope, subscriptionName); |
|
|
|
}); |
|
|
|
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>(); |
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); |
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>(); |
|
|
|
var eventBusSubscriptionManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |
|
|
|
string subscriptionName = configuration["SubscriptionClientName"]; |
|
|
|
|
|
|
|
return new EventBusServiceBus(serviceBusPersisterConnection, logger, |
|
|
|
eventBusSubscriptionManager, iLifetimeScope, subscriptionName); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>(sp => |
|
|
|
{ |
|
|
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>(sp => |
|
|
|
var subscriptionClientName = configuration["SubscriptionClientName"]; |
|
|
|
var rabbitMQPersistentConnection = sp.GetRequiredService<IRabbitMQPersistentConnection>(); |
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); |
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusRabbitMQ>>(); |
|
|
|
var eventBusSubscriptionManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |
|
|
|
|
|
|
|
var retryCount = 5; |
|
|
|
if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) |
|
|
|
{ |
|
|
|
var subscriptionClientName = configuration["SubscriptionClientName"]; |
|
|
|
var rabbitMQPersistentConnection = sp.GetRequiredService<IRabbitMQPersistentConnection>(); |
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); |
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusRabbitMQ>>(); |
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |
|
|
|
|
|
|
|
var retryCount = 5; |
|
|
|
if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) |
|
|
|
{ |
|
|
|
retryCount = int.Parse(configuration["EventBusRetryCount"]); |
|
|
|
} |
|
|
|
retryCount = int.Parse(configuration["EventBusRetryCount"]); |
|
|
|
} |
|
|
|
|
|
|
|
return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager, subscriptionClientName, retryCount); |
|
|
|
}); |
|
|
|
} |
|
|
|
return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubscriptionManager, subscriptionClientName, retryCount); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); |
|
|
|
services.AddTransient<ProductPriceChangedIntegrationEventHandler>(); |
|
|
|
services.AddTransient<OrderStatusChangedToShippedIntegrationEventHandler>(); |
|
|
|
services.AddTransient<OrderStatusChangedToPaidIntegrationEventHandler>(); |
|
|
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); |
|
|
|
services.AddTransient<ProductPriceChangedIntegrationEventHandler>(); |
|
|
|
services.AddTransient<OrderStatusChangedToShippedIntegrationEventHandler>(); |
|
|
|
services.AddTransient<OrderStatusChangedToPaidIntegrationEventHandler>(); |
|
|
|
|
|
|
|
return services; |
|
|
|
return services; |
|
|
|
} |
|
|
|
|
|
|
|
public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) |
|
|
|
{ |
|
|
|
var accountName = configuration.GetValue<string>("AzureStorageAccountName"); |
|
|
|
var accountKey = configuration.GetValue<string>("AzureStorageAccountKey"); |
|
|
|
|
|
|
|
var hcBuilder = services.AddHealthChecks(); |
|
|
|
|
|
|
|
hcBuilder |
|
|
|