我使用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)
你这个帮助是高度赞赏, 卡瓦