wpf 我应该创建什么而不是 Bootstrapper?棱镜 6.1.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33649240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What should I create instead of Bootstrapper? Prism 6.1.0
提问by StepUp
I've tried to update my application from Prism v4.0 to Prism v6.1.0 and run package manager: PM> Install-Package Prism.Core
我尝试将我的应用程序从 Prism v4.0 更新到 Prism v6.1.0 并运行包管理器:PM> Install-Package Prism.Core
and PM has installed such packages:
并且 PM 已经安装了这样的软件包:
- Microsoft.Practices.Prism.Composition.dll
- Microsoft.Practices.Prism.Interactivity.dll
- Microsoft.Practices.Prism.Mvvm.dll
- Microsoft.Practices.Prism.Mvvm.Desktop.dll
- Microsoft.Practices.Prism.PubSubEvents.dll
- Microsoft.Practices.Prism.SharedInterfaces.dll
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Prism.Composition.dll
- Microsoft.Practices.Prism.Interactivity.dll
- Microsoft.Practices.Prism.Mvvm.dll
- Microsoft.Practices.Prism.Mvvm.Desktop.dll
- Microsoft.Practices.Prism.PubSubEvents.dll
- Microsoft.Practices.Prism.SharedInterfaces.dll
- Microsoft.Practices.ServiceLocation.dll
The next step I've tried to create bootstrapper:
下一步我尝试创建引导程序:
public class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return Container.Resolve<Shell>();
}
protected override void InitializeShell()
{
base.InitializeShell();
App.Current.MainWindow = (Window)Shell;
App.Current.MainWindow.Show();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterType<IShellViewModel, ShellViewModel>();
}
protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
mappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>());
return mappings;
}
protected override IModuleCatalog CreateModuleCatalog()
{
ModuleCatalog catalog = new ModuleCatalog();
catalog.AddModule(typeof(ModuleBModule));
return catalog;
}
}
and I've tried to resolve the UnityBootstrapper. However, there is no such a class at Prism 6.1.0.
So I've tried to install by Nuget:
我试图解决UnityBootstrapper. 但是,Prism 6.1.0 中没有这样的类。所以我尝试通过 Nuget 安装:
Prism.UnityExtesions
However NuGet says: This package is no longer supported. Please use the new Prism.Unity package.
但是 NuGet 说:This package is no longer supported. Please use the new Prism.Unity package.
There is a bootstrapper class with Prism 5.0. But Prism 5.0 is not supported now. For example, in this example HelloWorldfrom code.msdn.
Prism 5.0 有一个引导程序类。但现在不支持 Prism 5.0。例如,在此示例中,来自 code.msdn 的HelloWorld。
So to my mind come the question: How to create bootstrapper at Prism 6.1.0?
所以我想到了一个问题:如何在 Prism 6.1.0 中创建引导程序?
回答by Bart
As mentioned in the comments by @toumir, first uninstall all Microsoft.Practices.*packages (check your packages.config to be sure they're all uninstalled).
正如@toumir 在评论中提到的,首先卸载所有Microsoft.Practices.*软件包(检查您的 packages.config 以确保它们都已卸载)。
Since you're trying to use Unity with Prism 6, the onlypackage you have to install is Prism.Unity. This will automatically bring in all other packages needed:
由于您尝试将 Unity 与 Prism 6 一起使用,您唯一需要安装的包是Prism.Unity。这将自动引入所需的所有其他包:
- Unity
- CommonServiceLocator
- Prism.Wpf
- Prism.Core
- 统一
- 公共服务定位器
- 棱镜
- 棱镜核心
It's a good practice to only add the most specific package, as with the new project files (.NET Core, ASP.NET 5, Win10 UWP) the old packages.config file is replaced by a project.json file and NuGet v3 will take care of better dependency resolving. As of today it's not used yet for WPF, but that shouldn't keep you from doing it "right".
最好只添加最具体的包,因为对于新项目文件(.NET Core、ASP.NET 5、Win10 UWP),旧的 packages.config 文件被 project.json 文件替换,NuGet v3 将采用照顾更好的依赖解决。截至今天,它还没有用于 WPF,但这不应该阻止您“正确”地做到这一点。
For new documentationand sampleson Prism 6, please head over to the Prism GitHub repositories.

