我使用PRISM 4,並且幾乎掌握了所有功能,但是隻要我想將我的DomainContext類(RIA)注入到視圖模型中,地獄就會鬆動。 :)如果有經驗的Unity/Prism開發人員可以給我一個建議如何繼續,那將是非常棒的。統一:解決RIA的問題DomainContext
在我的引導程序,我註冊在Unity集裝箱所需的類是這樣的:
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterType<SCMDomainContext>();
}
內NavigationModule,在構造函數我有以下的與特定區域註冊NavigationView。
public NavigationModule(IUnityContainer container, IRegionManager regionManager)
{
_container = container;
_regionManager = regionManager;
_regionManager.RegisterViewWithRegion(Constants.NavRegion,() => _container.Resolve<NavigationView>());
}
觀需要視圖模型的依賴性:
public NavigationView(NavigationViewModel viewModel)
{
InitializeComponent();
Loaded += (s, e) =>
{
DataContext = viewModel;
};
}
視圖模型有以下幾點:
public NavigationViewModel(SCMDomainContext context)
{
_context = context;
ConstructCommon();
}
當我評論這個構造函數,並把一個帶空的構造函數,這一切都很好,出於某種原因,我無法解決SCMDomainContext類。 Ria Services提供的是爲您創建的域上下文。
由於我使用的是Silverlight,我看不到跟蹤異常的堆棧跟蹤,我得到的只是此頁面上的消息。請問我錯過了什麼?
Microsoft JScript runtime error: Unhandled Error in Silverlight Application An exception occurred while initializing module 'NavigationModule'.
- The exception message was: Activation error occured while trying to get instance of type NavigationModule, key ''
Check the InnerException property of the exception for more information. If the exception occurred
while creating an object in a DI container, you can exception.GetRootException() to help locate the
root cause of the problem. at Microsoft.Practices.Prism.Modularity.ModuleInitializer.HandleModuleInitializationError(ModuleInfo moduleInfo, String assemblyName, Exception exception)
at Microsoft.Practices.Prism.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)
at Microsoft.Practices.Prism.Modularity.ModuleManager.LoadModulesThatAreReadyForLoad()
at Microsoft.Practices.Prism.Modularity.ModuleManager.IModuleTypeLoader_LoadModuleCompleted(Object sender, LoadModuleCompletedEventArgs e)
at Microsoft.Practices.Prism.Modularity.XapModuleTypeLoader.RaiseLoadModuleCompleted(LoadModuleCompletedEventArgs e)
at Microsoft.Practices.Prism.Modularity.XapModuleTypeLoader.HandleModuleDownloaded(DownloadCompletedEventArgs e)
at Microsoft.Practices.Prism.Modularity.XapModuleTypeLoader.IFileDownloader_DownloadCompleted(Object sender, DownloadCompletedEventArgs e)
at Microsoft.Practices.Prism.Modularity.FileDownloader.WebClient_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
at System.Net.WebClient.OpenReadOperationCompleted(Object arg)
你這個幫助是高度讚賞, 卡瓦