I’m new to C# but exp in Spring in Java. I can reproduce my problem quiet easily using the Spring example project Spring.WcfQuickStart.2010.
In the Spring.WcfQuickStart.ServerApp.2010 project do the following
1) Add the following TestDI class.
namespace Spring.WcfQuickStart
{
public class TestDI
{
public int test { get; set; }
public TestDI()
{
this.test = 10;
Console.WriteLine("TestDI cons called, value set to {0}", test);
}
}
}
2) In CalculatorService.cs, return “ServerApp Calculator testDI value=” + tdi.test;
3) In App.config do the following.
<object id="testObj" type="Spring.WcfQuickStart.TestDI, Spring.WcfQuickStart.ServerApp" singleton="true"/>
<object id="calculator" singleton="true"
type="Spring.WcfQuickStart.CalculatorService, Spring.WcfQuickStart.ServerApp">
<property name="tdi" ref="testObj"/>
<property name="SleepInSeconds" value="1"/>
</object>
Now, if you run the program you would expect that the client would be returned the value 10 but I am getting the value 0. This is the same for any property I define. If the TestDI properties test is changed to be static, same issue.
The only way to prevent this and get the value 10 is to remove the following from the App.config file.
<object id="serviceOperation" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
<property name="pattern" value="Spring.WcfQuickStart.*"/>
</object>
I could also just change the value=”Spring.WcfQuickStart.*” to be something else but then I have no aspects for my code.
Any help greatly appreciated.
Try setting your properties as ‘virtual’. I have found that if the properties are not virtual when working with AOP, often you will see null/default values.