PDA

View Full Version : Proxied object as dependency


kevwil
11-17-2006, 09:31 PM
I am trying to use a proxied object (AOP) as a constructor-arg dependency. When I request my final object from the app context, my intent is that it's dependency is resolved from the proxy factory and has the AOP advice applied. Here's my config:

<object id="debug.interceptor" type="Spring.Aop.Advice.DebugAdvice,Spring.Aop"/>
<object id="auth.service.target" type="TestSiteSpring.CustomAuthService,TestSiteSpring" singleton="false"/>
<object id="auth.service" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="target" value="auth.service.target"/>
<property name="proxyInterfaces">
<list>
<value>TestSiteSpring.IAuthService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>debug.interceptor</value>
</list>
</property>
</object>
<object id="complex.controller" type="TestSiteSpring.Controllers.ComplexController, TestSiteSpring" singleton="false">
<constructor-arg name="logger" ref="log4net.wrapper"/>
<constructor-arg name="authService" ref="auth.service" type="TestSiteSpring.IAuthService, TestSiteSpring"/>
</object>

The following unit test fails:

IApplicationContext context = ContextRegistry.GetContext();
Assert.IsNotNull( context );
object svc = context[ "auth.service" ];
Assert.IsInstanceOfType( typeof( IAuthService ), svc );

With the above config, I get an ArgumentException "Interface not found". If I leave out the 'proxyInterfaces' property, I get this UnsatisfiedDependencyException:

Error creating object with name 'complex.controller' defined in 'config [objects]' : Unsatisfied dependency expressed through constructor argument with index 1 of type [TestSiteSpring.IAuthService] : Could not convert constructor argument value [auth.service.target] to required type [TestSiteSpring.IAuthService] : Cannot convert property value of type [Spring.Aop.DynamicProxy.Proxy_c81fe12774194a828326 6675eaf64b60] to required type [TestSiteSpring.IAuthService] for property ''.

I'm new to Spring.NET, so I'm sure I'm doing something wrong. Can anyone find it?

Edit: I forgot to mention this is version 1.0.2 in a .NET 2.0 app.

Erich Eichinger
11-18-2006, 12:51 PM
Hi,

Shouldn't the line

<property name="target" value="auth.service.target"/>

read

<property name="target" ref="auth.service.target"/>

?

Btw: You should give the latest nightly (http://www.springframework.net/downloads/nightly/) build a try. There have been a lot of bugfixes, changes and improvements since 1.0.2. Since we're about to release 1.1, the API is quite stable now.

cheers,
Erich

kevwil
11-19-2006, 05:49 PM
That was it!

Thanks very much. :)