Microsoft Unity:使用 BuildUp 而不是 Resolve 时拦截不起作用
我正在使用 Microsoft Unity 2.0,拦截扩展未按预期工作。
考虑这两行代码:
MyUnityContainer.Configure<Interception>().SetDefaultInterceptorFor<MyType>(new VirtualMethodInterceptor());
var someObject = MyUnityContainer.BuildUp<MyType>(anObject);
这两行代码不会为您提供您期望的某个对象的动态代理!在这种情况下如何才能实现拦截呢?
I am using Microsoft Unity 2.0 and the interception extension is not working as expected.
Consider these two lines of code:
MyUnityContainer.Configure<Interception>().SetDefaultInterceptorFor<MyType>(new VirtualMethodInterceptor());
var someObject = MyUnityContainer.BuildUp<MyType>(anObject);
These two lines don't get you the dynamic proxy you'd expect for someObject! How can one make interception work for such a scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此页面说明您无法使用
BuildUp 来使用虚拟拦截
因为它只能在创建对象时应用(因为目标对象的子类是动态生成的):This page explains that you cannot use virtual interception using
BuildUp
since it can only be applied when the object is created (since a subclass of the target object is dynamically generated):VirtualMethodInterceptor 仅适用于新对象。您可以使用Interface 或TransparentProxy 拦截器来拦截现有实例(因为它们使用显式代理对象)。
我可以看到可能添加一个 VirtualMethodProxyInterceptor,但我预计它只会造成更多的混乱而不是帮助。
VirtualMethodInterceptor works only on new objects. You could use the Interface or TransparentProxy interceptors instead to intercept an existing instance (since those use explicit proxy objects).
I could see possibly adding a VirtualMethodProxyInterceptor, but I expect it'd just cause more confusion than help.