2017-05-26 70 views
0

我有一个.net application,它使用Spring.net。 也有一个interface的2个实现。应该使用哪一个 - 它基于configuration fileSpring.net ContextRegistry.GetContext失败,2接口实现

bootstrap为Spring有

<objects> 
<object id="Impl1" name="Impl1" type="namespace.Impl1, IInterface" > 
    </object> 
    <object id="Impl2" name="Impl2" type="namespace.Impl2, IInterface" > 
    </object> 
</objects> 

它未能上

var appContext = ContextRegistry.GetContext(); 

的错误信息是:

类型 'System.Configuration.ConfigurationErrorsException' 的未处理的异常发生在 Spring.Core.dll

其他信息:预期 单个匹配的对象,但发现2:: 系统类型[namespace.IInterface]被定义的无 独特对象:不合格依赖通过 构造器参数类型为[namespace.IInterface]的索引2表示.Collections.Specialized.OrderedDictionary

回答

0

我发现了另一个配置,其中autowire设置被设置为autodetect。

<object id="workspaceExportService" type="namespace.Imp3, Namespace" 
      autowire="autodetect" /> 

该类Imp3IInterface参数的构造函数。因此,它试图解决IInterface的实施,但找到其中两个。

作为解决方案,您可以将lazy-init="true"属性添加到对象节点。