Add dependency injection for global exception handler
Introduce methods in DependencyInjection.cs for configuring and using a global exception handler. Update the project file to include a reference to Microsoft.Extensions.Options. Modify GlobalExceptionHandlerMiddleware to accept IOptions<GlobalExceptionHandlerOptions> for enhanced configuration through dependency injection.
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.Core.Exceptions.Middleware;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection ConfigureGlobalExceptionHandler(this IServiceCollection services, Action<GlobalExceptionHandlerOptions> options)
|
||||
{
|
||||
return services.Configure(options);
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseGlobalExceptionHandler(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseMiddleware<GlobalExceptionHandlerMiddleware>();
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user