Skip to content

Commit

Permalink
Merge pull request #1956 from Ich1goSan/feature/webhooks-api-refactoring
Browse files Browse the repository at this point in the history
minor refactoring of Webhooks.API
  • Loading branch information
erjain authored Sep 2, 2022
2 parents 1807e95 + 7554b03 commit efb39de
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

public class HttpGlobalExceptionFilter : IExceptionFilter
{
private readonly IWebHostEnvironment env;
private readonly ILogger<HttpGlobalExceptionFilter> logger;
private readonly IWebHostEnvironment _env;
private readonly ILogger<HttpGlobalExceptionFilter> _logger;

public HttpGlobalExceptionFilter(IWebHostEnvironment env, ILogger<HttpGlobalExceptionFilter> 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);

Expand All @@ -26,7 +26,7 @@ public void OnException(ExceptionContext context)
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;
Expand All @@ -35,12 +35,12 @@ public void OnException(ExceptionContext context)
{
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);
Expand All @@ -53,6 +53,6 @@ private class JsonErrorResponse
{
public string[] Messages { get; set; }

public object DeveloperMeesage { get; set; }
public object DeveloperMessage { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ private bool CheckSameOrigin(string urlHook, string url)

return firstUrl.Scheme == secondUrl.Scheme &&
firstUrl.Port == secondUrl.Port &&
firstUrl.Host == firstUrl.Host;
firstUrl.Host == secondUrl.Host;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class IdentityService : IIdentityService
{
private IHttpContextAccessor _context;
private readonly IHttpContextAccessor _context;

public IdentityService(IHttpContextAccessor context)
{
Expand Down
71 changes: 34 additions & 37 deletions src/Services/Webhooks/Webhooks.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected virtual void ConfigureEventBus(IApplicationBuilder app)
}
}

static class CustomExtensionMethods
internal static class CustomExtensionMethods
{
public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration)
{
Expand Down Expand Up @@ -171,53 +171,50 @@ public static IServiceCollection AddSwagger(this IServiceCollection services, IC
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
Expand Down

0 comments on commit efb39de

Please sign in to comment.