我有一個非常基本的棱鏡應用程序,我試圖用它作爲一個大項目的開始。我有一個定義爲「MainContent」的單個區域的shell。項目中有3個模塊。 MainMenuModule,MovieModule和TVModule。電影和電視模塊依賴於MainMenuModule。模塊使用DirectoryModuleCatalog加載。當包含TVModule時會出現該問題,更具體地說,當調用TVModule的構造函數時會引發異常。如果我改變構造函數中我沒有得到任何異常,TVModule負載預期以下WPF Prism模塊錯誤解決IUnityContainer
public TVModule(IUnityContainer container, IRegionManager manager)
{
_container = container;
_manager = manager;
}
:構造下面將拋出一個錯誤。
public TVModule(IRegionManager manager)
{
_manager = manager;
}
當Unity試圖解析IUnityContainer時,我得到的異常被拋出。令我困惑的是,MovieModule的構造器與TVModule的構造器完全相同,而且沒有問題。例外細節。
{"Resolution of the dependency failed, type = \"TVModule.TVModule\", name = \"(none)\". Exception occurred while: while resolving. Exception is: InvalidOperationException - The current type, Microsoft.Practices.Unity.IUnityContainer, is an interface and cannot be constructed. Are you missing a type mapping? At the time of the exception, the container was:
Resolving TVModule.TVModule,(none) Resolving parameter \"container\" of constructor TVModule.TVModule(Microsoft.Practices.Unity.IUnityContainer container, Microsoft.Practices.Prism.Regions.IRegionManager manager) Resolving Microsoft.Practices.Unity.IUnityContainer,(none) "}
{"The current type, Microsoft.Practices.Unity.IUnityContainer, is an interface and cannot be constructed. Are you missing a type mapping?"}
編輯:我已經上傳我的源代碼拷貝到收存箱here
您是否註冊了兩個模塊到UnityContainer?與「TVModule」相比,「MovieModule」的設置/註冊方式有什麼不同? – ryrich 2013-03-20 18:17:23
除了形成MovieModule之外,沒有什麼不同之處,它有一個額外的視圖,即TVModule沒有。隨意從我添加到我的問題的保管箱鏈接下載我的源代碼。 – OriginalMoose 2013-03-20 18:47:14
這不是一個答案,而是一個很好的建議:你應該避免以明確的方式在類之間傳遞ioc容器。它是支持解析服務的容器,但容器本身不是商業服務。傳遞一個容器使得你的類依賴於不好的容器 - ioc應該幫助你而不是破壞你的代碼。 – 2013-03-20 18:51:52