Prism应用程序中的奇怪异常 [英] Strange exception in Prism application

查看:677
本文介绍了Prism应用程序中的奇怪异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试启动Prism应用程序,并且遇到一个非常奇怪的错误:

I am trying to get a Prism application to start up, and am getting a very strange error:

InvalidOperationException:必须设置ServiceLocationProvider.

InvalidOperationException: ServiceLocationProvider must be set.

我在主(模块主机)应用程序中使用MainWindow作为单个主shell的区域,该主shell具有自己的区域.这样,我可以根据需要交换主窗口布局.

I am using MainWindow in the main (module host) application as the region for a single main shell, that has it's own regions. That way I can swap out main window layouts if needed.

我在InitializeComponent();调用中得到了错误,这是MainWindow的构造函数中的唯一代码行. Google和Bing对该确切词组均返回零结果.

I get the error on the InitializeComponent(); call, the only line of code in the constructor of MainWindow. Google and Bing both return zero results for that exact phrase.

MainWindow中的XAML元素是:

The XAML element in MainWindow is:

<ContentControl regions:RegionManager.RegionName="MainShellRegion" />

我是否必须在MainWindow上实现一些接口或某些东西来解决此问题?我完全迷住了.

Do I have to implement some interface or something on MainWindow to solve this? I am completely stumped.

推荐答案

您需要为Prism应用程序设置依赖项注入,否则它将无法运行.这应该从您的 bootstrapper ,在

You need to set up dependency injection for your Prism application, otherwise it won't be able to run. This should be done from inside your bootstrapper, inside the ConfigureServiceLocator method.

为了进一步说明上述内容,对Prism进行了布线,以便在需要访问应用程序组件时,它不会直接初始化该组件(它将如何知道要使用哪个实现以及如何对其进行初始化?),而是对其进行了初始化.将这项工作委托给服务定位器.

To expand a bit on the above, Prism is wired so that whenever it needs access to an application component it does not initialize the component directly (how would it know which implementation to use and how to initialize it?) but rather it delegates this job to a service locator.

服务定位器是一个组件,负责履行对另一组件提出的一个组件的请求,从而允许两个组件分离.作为开发人员,您有责任实例化和配置服务定位器并将其提供给Prism;这是在应用程序启动期间完成的(因此在引导程序内部).

The service locator is a component whose responsibility is to fulfill requests for one component made by another, allowing the two components to be decoupled. It is your responsibility as the developer to instantiate and configure the service locator and make it available to Prism; this is done during application startup (hence inside the bootstrapper).

这篇关于Prism应用程序中的奇怪异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆