【发布时间】:2019-03-19 14:37:37
【问题描述】:
我正在尝试为我的所有控制器添加一个拦截器。我正在使用 Simple Injector 和 asp.net MVC。
在尝试此示例时:https://simpleinjector.readthedocs.io/en/latest/InterceptionExtensions.html 当我想将拦截器添加到接口时,一切正常。问题从控制器开始,因为它们是具体类型而不是接口......
private static void ThrowIfServiceTypeNotInterface(ExpressionBuiltEventArgs e) {
// NOTE: We can only handle interfaces, because
// System.Runtime.Remoting.Proxies.RealProxy only supports interfaces.
if (!e.RegisteredServiceType.IsInterface) {
throw new NotSupportedException("Can't intercept type " +
e.RegisteredServiceType.Name + " because it is not an interface.");
}
}
在上面的实现中,仅对接口有明确的限制,我想了解为什么?
有没有人有在 SimpleInjector 中为控制器/具体类型添加拦截器的经验?
【问题讨论】:
标签: asp.net-mvc aop simple-injector