dziegel
04-19-2007, 02:55 PM
Hello,
I've created this test:
using System;
using Spring.Context.Support;
using System.Reflection;
using System.Diagnostics;
namespace SpringProxying
{
public interface Interface1
{
void FunctionInterface1();
}
public interface Interface2
{
void FunctionInterface2();
}
public class ToBeProxied: Interface1, Interface2
{
private int m_someValue = 0;
public ToBeProxied()
{
}
public int someValue
{
get
{
return m_someValue;
}
}
#region Interface1 Member
void Interface1.FunctionInterface1()
{
m_someValue = 1;
}
#endregion
#region Interface2 Member
void Interface2.FunctionInterface2()
{
m_someValue = 2;
}
#endregion
};
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlApplicationContext c = new XmlApplicationContext("assembly://SpringProxying/SpringProxying/Spring.xml");
ToBeProxied proxied = (ToBeProxied)c.GetObject("proxiedClass");
ToBeProxied unproxied = (ToBeProxied)c.GetObject("unproxiedClass");
// target of proxiedClass == unproxiedClass since unproxiedClass is a singleton
// ProxyTargetType == true
// ProxyInterfaces = ['Interface1'] --- -> Interface2 is NOT proxied!
Debug.WriteLine("Unproxied: " + unproxied.someValue); // Prints "0"
Debug.WriteLine("Proxied: " + proxied.someValue); // Prints "0"
(proxied as Interface1).FunctionInterface1();
Debug.WriteLine("Unproxied: " + unproxied.someValue); // Prints "1"
Debug.WriteLine("Proxied: " + proxied.someValue); // Prints "0"
(proxied as Interface2).FunctionInterface2();
Debug.WriteLine("Unproxied: " + unproxied.someValue); // Prints "1"
Debug.WriteLine("Proxied: " + proxied.someValue); // Prints "2"
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="unproxiedClass" type="SpringProxying.ToBeProxied" singleton="true" />
<object id="proxiedClass" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="Target" ref="unproxiedClass" />
<property name="ProxyTargetType" value="true" />
<property name="ProxyInterfaces">
<list>
<value>SpringProxying.Interface1</value>
</list>
</property>
</object>
</objects>
Am I misusing Spring if I mix ProxyTargetType=true with ProxyInterface=[<list>]?
It seems Spring does not redirect the unproxied call to FunctionInterface2() to the target. I wanted to use this as a simple way to intercept only calls to FunctionInterface1() in my app...
VS 2003 ZIP archive available on request for debugging.
Spring Nightly 20070418-1234.
Dirk
I've created this test:
using System;
using Spring.Context.Support;
using System.Reflection;
using System.Diagnostics;
namespace SpringProxying
{
public interface Interface1
{
void FunctionInterface1();
}
public interface Interface2
{
void FunctionInterface2();
}
public class ToBeProxied: Interface1, Interface2
{
private int m_someValue = 0;
public ToBeProxied()
{
}
public int someValue
{
get
{
return m_someValue;
}
}
#region Interface1 Member
void Interface1.FunctionInterface1()
{
m_someValue = 1;
}
#endregion
#region Interface2 Member
void Interface2.FunctionInterface2()
{
m_someValue = 2;
}
#endregion
};
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlApplicationContext c = new XmlApplicationContext("assembly://SpringProxying/SpringProxying/Spring.xml");
ToBeProxied proxied = (ToBeProxied)c.GetObject("proxiedClass");
ToBeProxied unproxied = (ToBeProxied)c.GetObject("unproxiedClass");
// target of proxiedClass == unproxiedClass since unproxiedClass is a singleton
// ProxyTargetType == true
// ProxyInterfaces = ['Interface1'] --- -> Interface2 is NOT proxied!
Debug.WriteLine("Unproxied: " + unproxied.someValue); // Prints "0"
Debug.WriteLine("Proxied: " + proxied.someValue); // Prints "0"
(proxied as Interface1).FunctionInterface1();
Debug.WriteLine("Unproxied: " + unproxied.someValue); // Prints "1"
Debug.WriteLine("Proxied: " + proxied.someValue); // Prints "0"
(proxied as Interface2).FunctionInterface2();
Debug.WriteLine("Unproxied: " + unproxied.someValue); // Prints "1"
Debug.WriteLine("Proxied: " + proxied.someValue); // Prints "2"
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="unproxiedClass" type="SpringProxying.ToBeProxied" singleton="true" />
<object id="proxiedClass" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="Target" ref="unproxiedClass" />
<property name="ProxyTargetType" value="true" />
<property name="ProxyInterfaces">
<list>
<value>SpringProxying.Interface1</value>
</list>
</property>
</object>
</objects>
Am I misusing Spring if I mix ProxyTargetType=true with ProxyInterface=[<list>]?
It seems Spring does not redirect the unproxied call to FunctionInterface2() to the target. I wanted to use this as a simple way to intercept only calls to FunctionInterface1() in my app...
VS 2003 ZIP archive available on request for debugging.
Spring Nightly 20070418-1234.
Dirk