版本:C# 4.0、Spring.Net 1.3.2、RhinoMocks 3.6.1
给定这两个接口:
public interface IDivisionSelectView
{
// ...
}
public interface ILoginView
{
IDivisionSelectView DivisionSelectView { get; }
// ...
}
我正在尝试使用 Spring.Net 使用Rhino.Mocks.MockRepository.GenerateMock<>()
工厂创建一个代理对象,ILoginView
该对象的DivisionSelectView属性自动设置为IDivisionSelectView
代理(使用相同的工厂)。这是 Spring XML:
<object id="IDivisionSelectView"
type="Rhino.Mocks.MockRepository, Rhino.Mocks"
factory-method="GenerateMock<[Asm.Ns.IDivisionSelectView, Asm]>"
singleton="false">
<constructor-arg name="argumentsForConstructor">
<list element-type="System.Object, mscorlib">
</list>
</constructor-arg>
</object>
<object id="ILoginView"
type="Rhino.Mocks.MockRepository, Rhino.Mocks"
factory-method="GenerateMock<[Asm.Ns.ILoginView, Asm]>"
singleton="false">
<constructor-arg name="argumentsForConstructor">
<list element-type="System.Object, mscorlib">
</list>
</constructor-arg>
<property name="DivisionSelectView" ref="IDivisionSelectView">
</property>
</object>
这是调用 C# 代码:
IApplicationContext ctx = new XmlApplicationContext(
"assembly://Asm/Asm/spring.xml");
ContextRegistry.RegisterContext(ctx);
ILoginView view = ctx.GetObject("ILoginView") as ILoginView;
这是我得到的错误:
Spring.Objects.Factory.ObjectCreationException was unhandled by user code
Message=Error creating object with name 'ILoginView' defined in 'assembly [Asm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], resource [Asm.spring.xml] line 14' : Initialization of object failed : 'DivisionSelectView' node cannot be resolved for the specified context [Castle.Proxies.ILoginViewProxy4fa9c3fa65ca497bb09ce6358d876e4d].
这可能吗?