在类库项目中使用ActionFilterAttribute(.NET)
答
不是没有比它的价值更多的麻烦。动作过滤器是Web Api的一项功能,因此除非您正在讨论将Web Api控制器放入您自己的库中,或者在Web Api控制器中使用库中的过滤器,否则您将无法直接利用它们。
一个潜在的解决方案可能是使用proxy pattern或decorator pattern来为您的库处理cross-cutting concerns。详情请看Aspect-Oriented Programming : Aspect-Oriented Programming with the RealProxy Class。