PDA

View Full Version : Constructor Interceptor



oguz
09-06-2006, 01:01 AM
Hi all,
I'm trying intercept an object contrsuction where I don't control the caller object so dependencies can be injected that would normally when the caller gets the object via spring (in a web application via the httphandler)

Specifically: I have a BO that is injected into an aspx that gets data from the DAO.The BO is injected with the DAO and all is fine.

However if I use an <asp:ObjectDataSource .../> that calls the BO, a new instance of the BO is created by <asp:ObjectDataSource ../> without an injected DAO.

I've tried this (which doesn't work)


<object name="MyBo" type="Namespace.MyBo, App_Code">
<property name="MyDao" ref="MyDao" />
</object>
...
<object name="MyBoSingleton" type="Spring.Aop.Target.SingletonTargetSource">
<constructor-arg name="target" ref="MyBo" />
</object>


Does anyone have suggestions on how to intercept MyBo's constructor and inject the required DAO?

Thanks,
Oz

oguz
09-06-2006, 01:10 AM
Hi again,

I've had a futher look around the doco and there is an empty section on Proxying Classes: "This functionalty is not yet available. Stay tuned!". Is this the case I should be looking out for when it's implemented or is something available now?

Also does anyone know if Castle supports something like this?

Thanks
Oz

oguz
09-06-2006, 01:16 AM
Hi yet again,
There is another post: use dynamic proxy on none interface implemented object (http://forum.springframework.net/showthread.php?t=260)

I think this is the same sort of issue - or am I barking up the wrong tree? Are there any plans to implement this feature?

Thanks,
Oz

oguz
09-06-2006, 04:28 AM
Hi all,

I haven't quite worked out how to implement this yet but I've used an alternate solution by setting the Datasource BO Instance in the in the OnObjectCreating eventhandler to be the instance injected into the page.

I would though still like to know if it is possible to intercept the constructor via Spring AOP?

Thanks
Oz

Bruno Baia
09-06-2006, 09:45 AM
Hi Oz,

actually, we can't intercept constructor via Spring AOP.
We planned (http://opensource.atlassian.com/projects/spring/browse/SPRNET-215) to support it for 1.2 version.

About Section 8.5.4 Proxying Classes, we just implemented it, documentation will be online soon.
It allows you to use Spring AOP on non interface implemented object as explained in the post you mentionned.
To test it, you need to get one of the latest nightly builds (http://www.springframework.net/downloads/nightly).


-Bruno