Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit efb39de

Browse files
authored
Merge pull request #1956 from Ich1goSan/feature/webhooks-api-refactoring
minor refactoring of Webhooks.API
2 parents 1807e95 + 7554b03 commit efb39de

File tree

4 files changed

+46
-49
lines changed

4 files changed

+46
-49
lines changed

src/Services/Webhooks/Webhooks.API/Infrastructure/HttpGlobalExceptionFilter.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
public class HttpGlobalExceptionFilter : IExceptionFilter
44
{
5-
private readonly IWebHostEnvironment env;
6-
private readonly ILogger<HttpGlobalExceptionFilter> logger;
5+
private readonly IWebHostEnvironment _env;
6+
private readonly ILogger<HttpGlobalExceptionFilter> _logger;
77

88
public HttpGlobalExceptionFilter(IWebHostEnvironment env, ILogger<HttpGlobalExceptionFilter> logger)
99
{
10-
this.env = env;
11-
this.logger = logger;
10+
_env = env;
11+
_logger = logger;
1212
}
1313

1414
public void OnException(ExceptionContext context)
1515
{
16-
logger.LogError(new EventId(context.Exception.HResult),
16+
_logger.LogError(new EventId(context.Exception.HResult),
1717
context.Exception,
1818
context.Exception.Message);
1919

@@ -26,7 +26,7 @@ public void OnException(ExceptionContext context)
2626
Detail = "Please refer to the errors property for additional details."
2727
};
2828

29-
problemDetails.Errors.Add("DomainValidations", new string[] { context.Exception.Message.ToString() });
29+
problemDetails.Errors.Add("DomainValidations", new [] { context.Exception.Message });
3030

3131
context.Result = new BadRequestObjectResult(problemDetails);
3232
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
@@ -35,12 +35,12 @@ public void OnException(ExceptionContext context)
3535
{
3636
var json = new JsonErrorResponse
3737
{
38-
Messages = new[] { "An error ocurred." }
38+
Messages = new[] { "An error occurred." }
3939
};
4040

41-
if (env.IsDevelopment())
41+
if (_env.IsDevelopment())
4242
{
43-
json.DeveloperMeesage = context.Exception;
43+
json.DeveloperMessage = context.Exception;
4444
}
4545

4646
context.Result = new InternalServerErrorObjectResult(json);
@@ -53,6 +53,6 @@ private class JsonErrorResponse
5353
{
5454
public string[] Messages { get; set; }
5555

56-
public object DeveloperMeesage { get; set; }
56+
public object DeveloperMessage { get; set; }
5757
}
5858
}

src/Services/Webhooks/Webhooks.API/Services/GrantUrlTesterService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ private bool CheckSameOrigin(string urlHook, string url)
4545

4646
return firstUrl.Scheme == secondUrl.Scheme &&
4747
firstUrl.Port == secondUrl.Port &&
48-
firstUrl.Host == firstUrl.Host;
48+
firstUrl.Host == secondUrl.Host;
4949
}
5050
}

src/Services/Webhooks/Webhooks.API/Services/IdentityService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class IdentityService : IIdentityService
44
{
5-
private IHttpContextAccessor _context;
5+
private readonly IHttpContextAccessor _context;
66

77
public IdentityService(IHttpContextAccessor context)
88
{

src/Services/Webhooks/Webhooks.API/Startup.cs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)