【发布时间】:2015-05-08 21:03:22
【问题描述】:
在 WebAPI 中处理 IExceptionHandler 的多个实现的最佳方法是什么?
config.Services.Replace(typeof(IExceptionHandler), new ExceptionHandlerFilter());
config.Services.Add(typeof(IExceptionHandler), new ValidationExceptionHandlerFilter());
当尝试注册多个实现时,启动会抛出异常:
不支持服务类型 IExceptionHandler。\r\n参数名称:serviceType
但 API 建议支持多个处理程序,因为有一个 ShouldHandle 属性可以覆盖 ExceptionHandler 类。
【问题讨论】:
标签: asp.net-web-api asp.net-web-api2