Spring.NET & 构造函数拦截器
我试图在构造时对对象进行一些 AOP,并找到了 IConstructorInterceptor,它非常适合我想要的,但它 似乎不起作用(至少在 1.2 版本中)。
我还查看了 IObjectPostProcessor 和 IObjectPostProcessor 。 IInstantiationAwareObjectPostProcessor,但我找不到任何方法在构造时对对象进行处理... IInstantiationAwareObjectPostProcessor 上的 PostProcessPropertyValues 方法很接近,但它只传递 setter 注入的属性而不是构造函数参数值...
具体是什么我想要的是对实例化后的对象的引用,同时也是对注入构造函数的对象的引用。 有什么办法可以做到这一点,或者我最好的选择是切换到设置器注入和设置器注入。 使用后处理器还是 MethodInterceptor?
I'm trying to do some AOP over objects at construction time, and found IConstructorInterceptor, which would be perfect for what I want but it doesn't appear to work (in version 1.2 at least).
I've also looked at both the IObjectPostProcessor & the IInstantiationAwareObjectPostProcessor, but I can't find any way to do processing on an object around construction time... The PostProcessPropertyValues method on the IInstantiationAwareObjectPostProcessor is close, but it only passes through setter injected properties not the constructor arg values...
Specifically what I want is a reference to an object just after instantiation and at the same time, references to the objects that were injected into the constructor. Is there any way to do this, or is my best bet to just switch to setter injection & use the post processor or a MethodInterceptor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AOP提出调用拦截,而不是依赖注入。 使用 Spring.Net,您可以使用 seters 或构造函数来执行任何依赖项注入。 对于您的帖子和评论,它应该有效。
在 Spring.Net 初始化管道上,第一步分析依赖关系图,执行任何对象创建并设置所有依赖关系。 之后,如果您的类实现“Spring.Objects.Factory.IInitializingObject”,则方法“void AfterPropertiesSet();” 叫做。 其他执行方法是使用对象配置,您可以在对象节点上设置 init-method 。
此行为基于 IoC/DI 概念。
也许您需要创建一个特定的工厂对象。 为此,您的工厂必须实现 Spring.Objects.Factory.IFactoryObject 接口。 这有助于容器为您委托对象创建(此配置上的属性和构造函数适用于您的工厂)。
此致
AOP proposes call interception, not dependency injection. Using Spring.Net you can use seters or constructors to perform any dependency injection. For your post and comments, it supposed to work.
On Spring.Net initialization pipeline, first step analyse dependency graph, perform any object creation and set all dependencies. After that, if your class implement "Spring.Objects.Factory.IInitializingObject", the method "void AfterPropertiesSet();" is called. Other way to perform that is using your object configuration, you may setting init-method on object node.
This behavior is based in IoC/DI concepts.
Maybe you needs create a specific factory object. To perform that, your factory must implement Spring.Objects.Factory.IFactoryObject interface. That helps container to delegate for you the object creation (properties and constructors on this configuration are for your factory).
Best Regards