Spring.NET&功放;构造函数拦截器 [英] Spring.NET & Constructor Interceptors

查看:222
本文介绍了Spring.NET&功放;构造函数拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些AOP在施工时对象,并发现IConstructorInterceptor,这将是完美的我想要什么,但它的似乎并没有工作(在1.2版本中,至少)。

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).

我也看了两个IObjectPostProcessor和放大器;在IInstantiationAwareObjectPostProcessor,但我无法找到任何方式做处理围绕建设时间的物体上......在IInstantiationAwareObjectPostProcessor的PostProcessPropertyValues​​方法接近,但它只能通过setter方法​​注入的属性不是构造的arg值...

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...

具体是什么我要的只是实例化后,并在同一时间内对对象的引用,引用到注入的构造函数的对象。有没有办法做到这一点,或者是我最好的选择,只是切换到setter注入和放大器;使用后处理器或者和MethodInterceptor?

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?

推荐答案

AOP提出呼叫拦截,而不是依赖注入。使用Spring.Net你可以使用seters或构造函数来执行任何依赖注入。为您的文章和评论,就应该工作。

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.

在Spring.Net初始化管道,首先分析依赖图,执行任何对象创建和设置的所有依赖关系。在此之后,如果你的类实现Spring.Objects.Factory.IInitializingObject方法无效的afterPropertiesSet();被调用。其他的方法来执行正在使用的对象配置,你可以设置了init-method对象节点上。 此行为基于在IOC / DI概念。

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.

也许你需要创建一个具体的工厂对象。要执行,你的工厂必须实现Spring.Objects.Factory.IFactoryObject接口。这有助于容器委派为你创建对象(在此配置性能和构造是你的工厂)。

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).

最好的问候

这篇关于Spring.NET&功放;构造函数拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆