Multiple implementations of IExceptionHandler

What is the best way to handle multiple IExceptionHandler implementations in WebAPI?

 config.Services.Replace(typeof(IExceptionHandler), new ExceptionHandlerFilter()); config.Services.Add(typeof(IExceptionHandler), new ValidationExceptionHandlerFilter()); 

When trying to register more than 1 implementation, the launch throws an exception:

IExceptionHandler service type is not supported. \ R \ nParameter: serviceType

But the API offers several handlers, since the ShouldHandle property ShouldHandle for overriding in the ExceptionHandler class.

+5
source share
1 answer

You cannot register more than a IExceptionHandler

We support the registration of several exception logs, but only one exception handler.

source: Global error handling in the ASP.NET web interface

ShouldHandle properties ShouldHandle used to get only the exception at the top of the stack.

+4
source

Source: https://habr.com/ru/post/1214216/


All Articles