PDA

View Full Version : Proxy classes and null properties



villanum
06-03-2009, 07:01 PM
I have searched and searched for a similar problem like I'm having so forgive me if this has been answered before. I have a basic class that implements and interface. I setup an AOP proxy on this class so I could put an AfterReturningAdvice after one of its methods. The weirdness that I'm seeing is that I have one propery on the class (it is also in the interface) - if I set that property, and then later read it, it is always null.

Here is my interface:

public interface IRatings
{
string Test { get;set;}
string GetRatings(string assetId)
}

Here is my implementing class:

public class RatingsClass : IRatings
{
private string _test;

public string Test
{
get
{
return _test;
}
set
{
_test = value;
}
}

public string GetRatings(string AssetID)
{
// code
}
}

Here is my web.config:

<object id="ratingsHandler" name="RatingsHandler.ashx" type="RatingsRESTService.RatingsHandler, RatingsRESTService">
<lookup-method name="CreateRatingsClass" object="ratingsClassProxy"/>
</object>

<object id="ratingsClass" type="RatingsRESTService.RatingsClass, RatingsRESTService" singleton="false"/>

<object id="publishAdvice" type="Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop">
<property name="Advice">
<object id="publishEventAdvice"
type="RatingsRESTService.PublishEventAdvice, RatingsRESTService"/>
</property>
<property name="MappedNames">
<list>
<value>GetRatings*</value>
</list>
</property>
</object>

<object id="ratingsClassProxy" type="Spring.Aop.Framework.ProxyFactoryObject">

<property name="ProxyTargetType" value="true"/>
<property name="TargetSource">
<object type="Spring.Aop.Target.PrototypeTargetSource, Spring.Aop">
<property name="TargetObjectName" value="ratingsClass" />
</object>
</property>
<property name="InterceptorNames">
<list>
<value>publishAdvice</value>
</list>
</property>
</object>

And in my HttpHandler, I do this:


IRatings ratings = CreateRatingsClass();
ratings.Test = "myTest";

If I inspect ratings, the Test property is null. What am I doing wrong? Thanks!

Bruno Baia
07-07-2009, 09:37 PM
Hi,

remove the line :


<property name="ProxyTargetType" value="true"/>

or mark your properties/methods as virtual.

- Bruno