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"屬性添加到對象節點。