Phi*_*ill 5 asp.net-web-api asp.net-web-api2
IExceptionHandler在WebAPI中处理多个实现的最佳方法是什么?
config.Services.Replace(typeof(IExceptionHandler), new ExceptionHandlerFilter());
config.Services.Add(typeof(IExceptionHandler), new ValidationExceptionHandlerFilter());
Run Code Online (Sandbox Code Playgroud)
尝试注册多个实现时,启动会抛出异常:
不支持服务类型IExceptionHandler.\ r \nParameter name:serviceType
但API建议支持多个处理程序,因为有一个ShouldHandle属性可以覆盖ExceptionHandler类.
您无法注册更多IExceptionHandler
我们支持注册多个异常记录器,但仅支持一个异常处理程序。
该ShouldHandle属性用于仅获取堆栈顶部的异常