diff --git a/src/Services/Basket/Basket.API/CustomExtensionMethods.cs b/src/Services/Basket/Basket.API/CustomExtensionMethods.cs new file mode 100644 index 000000000..8fcbf0c28 --- /dev/null +++ b/src/Services/Basket/Basket.API/CustomExtensionMethods.cs @@ -0,0 +1,37 @@ +namespace Microsoft.eShopOnContainers.Services.Basket.API; + +public static class CustomExtensionMethods +{ + public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) + { + var hcBuilder = services.AddHealthChecks(); + + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + + hcBuilder + .AddRedis( + configuration["ConnectionString"], + name: "redis-check", + tags: new string[] { "redis" }); + + if (configuration.GetValue("AzureServiceBusEnabled")) + { + hcBuilder + .AddAzureServiceBusTopic( + configuration["EventBusConnection"], + topicName: "eshop_event_bus", + name: "basket-servicebus-check", + tags: new string[] { "servicebus" }); + } + else + { + hcBuilder + .AddRabbitMQ( + $"amqp://{configuration["EventBusConnection"]}", + name: "basket-rabbitmqbus-check", + tags: new string[] { "rabbitmqbus" }); + } + + return services; + } +} \ No newline at end of file diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index 4dc01fff2..7e0142c2c 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -282,40 +282,4 @@ public class Startup eventBus.Subscribe(); eventBus.Subscribe(); } -} - -public static class CustomExtensionMethods -{ - public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) - { - var hcBuilder = services.AddHealthChecks(); - - hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); - - hcBuilder - .AddRedis( - configuration["ConnectionString"], - name: "redis-check", - tags: new string[] { "redis" }); - - if (configuration.GetValue("AzureServiceBusEnabled")) - { - hcBuilder - .AddAzureServiceBusTopic( - configuration["EventBusConnection"], - topicName: "eshop_event_bus", - name: "basket-servicebus-check", - tags: new string[] { "servicebus" }); - } - else - { - hcBuilder - .AddRabbitMQ( - $"amqp://{configuration["EventBusConnection"]}", - name: "basket-rabbitmqbus-check", - tags: new string[] { "rabbitmqbus" }); - } - - return services; - } } \ No newline at end of file diff --git a/src/Services/Webhooks/Webhooks.API/Infrastructure/HttpGlobalExceptionFilter.cs b/src/Services/Webhooks/Webhooks.API/Infrastructure/HttpGlobalExceptionFilter.cs index a1ebf5c4c..39eab9908 100644 --- a/src/Services/Webhooks/Webhooks.API/Infrastructure/HttpGlobalExceptionFilter.cs +++ b/src/Services/Webhooks/Webhooks.API/Infrastructure/HttpGlobalExceptionFilter.cs @@ -2,18 +2,18 @@ public class HttpGlobalExceptionFilter : IExceptionFilter { - private readonly IWebHostEnvironment env; - private readonly ILogger logger; + private readonly IWebHostEnvironment _env; + private readonly ILogger _logger; public HttpGlobalExceptionFilter(IWebHostEnvironment env, ILogger logger) { - this.env = env; - this.logger = logger; + _env = env; + _logger = logger; } public void OnException(ExceptionContext context) { - logger.LogError(new EventId(context.Exception.HResult), + _logger.LogError(new EventId(context.Exception.HResult), context.Exception, context.Exception.Message); @@ -26,7 +26,7 @@ public class HttpGlobalExceptionFilter : IExceptionFilter Detail = "Please refer to the errors property for additional details." }; - problemDetails.Errors.Add("DomainValidations", new string[] { context.Exception.Message.ToString() }); + problemDetails.Errors.Add("DomainValidations", new [] { context.Exception.Message }); context.Result = new BadRequestObjectResult(problemDetails); context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; @@ -35,12 +35,12 @@ public class HttpGlobalExceptionFilter : IExceptionFilter { var json = new JsonErrorResponse { - Messages = new[] { "An error ocurred." } + Messages = new[] { "An error occurred." } }; - if (env.IsDevelopment()) + if (_env.IsDevelopment()) { - json.DeveloperMeesage = context.Exception; + json.DeveloperMessage = context.Exception; } context.Result = new InternalServerErrorObjectResult(json); @@ -53,6 +53,6 @@ public class HttpGlobalExceptionFilter : IExceptionFilter { public string[] Messages { get; set; } - public object DeveloperMeesage { get; set; } + public object DeveloperMessage { get; set; } } } diff --git a/src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs b/src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs index ea75ac343..9f480ddc3 100644 --- a/src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs +++ b/src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs @@ -45,6 +45,6 @@ class GrantUrlTesterService : IGrantUrlTesterService return firstUrl.Scheme == secondUrl.Scheme && firstUrl.Port == secondUrl.Port && - firstUrl.Host == firstUrl.Host; + firstUrl.Host == secondUrl.Host; } } diff --git a/src/Services/Webhooks/Webhooks.API/Services/IdentityService.cs b/src/Services/Webhooks/Webhooks.API/Services/IdentityService.cs index cd821dc74..6b7c580f8 100644 --- a/src/Services/Webhooks/Webhooks.API/Services/IdentityService.cs +++ b/src/Services/Webhooks/Webhooks.API/Services/IdentityService.cs @@ -2,7 +2,7 @@ public class IdentityService : IIdentityService { - private IHttpContextAccessor _context; + private readonly IHttpContextAccessor _context; public IdentityService(IHttpContextAccessor context) { diff --git a/src/Services/Webhooks/Webhooks.API/Startup.cs b/src/Services/Webhooks/Webhooks.API/Startup.cs index 256941efa..07325bcbc 100644 --- a/src/Services/Webhooks/Webhooks.API/Startup.cs +++ b/src/Services/Webhooks/Webhooks.API/Startup.cs @@ -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("AzureServiceBusEnabled")) + { + services.AddSingleton(sp => { - services.AddSingleton(sp => - { - var serviceBusPersisterConnection = sp.GetRequiredService(); - var iLifetimeScope = sp.GetRequiredService(); - var logger = sp.GetRequiredService>(); - var eventBusSubcriptionsManager = sp.GetRequiredService(); - string subscriptionName = configuration["SubscriptionClientName"]; - - return new EventBusServiceBus(serviceBusPersisterConnection, logger, - eventBusSubcriptionsManager, iLifetimeScope, subscriptionName); - }); + var serviceBusPersisterConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubscriptionManager = sp.GetRequiredService(); + string subscriptionName = configuration["SubscriptionClientName"]; + + return new EventBusServiceBus(serviceBusPersisterConnection, logger, + eventBusSubscriptionManager, iLifetimeScope, subscriptionName); + }); - } - else + } + else + { + services.AddSingleton(sp => { - services.AddSingleton(sp => + var subscriptionClientName = configuration["SubscriptionClientName"]; + var rabbitMQPersistentConnection = sp.GetRequiredService(); + var iLifetimeScope = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var eventBusSubscriptionManager = sp.GetRequiredService(); + + var retryCount = 5; + if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) { - var subscriptionClientName = configuration["SubscriptionClientName"]; - var rabbitMQPersistentConnection = sp.GetRequiredService(); - var iLifetimeScope = sp.GetRequiredService(); - var logger = sp.GetRequiredService>(); - var eventBusSubcriptionsManager = sp.GetRequiredService(); - - 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(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddSingleton(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); - return services; + return services; } public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) { - var accountName = configuration.GetValue("AzureStorageAccountName"); - var accountKey = configuration.GetValue("AzureStorageAccountKey"); - var hcBuilder = services.AddHealthChecks(); hcBuilder