C# 简单棱镜自举器

C# 简单棱镜自举器,c#,wpf,prism,C#,Wpf,Prism,我目前正在使用Prism 6将我的程序移植到,这是一个WPF应用程序。 所以我安装了Prism.Unity(6.1.1),它与Prism.Wpf(6.1.0)、Prism.Core(6.1.0)、Unity(4.0.1)和CommonServiceLocator(1.3.0)一起提供 然后我带来了那些棱镜样品,但看在上帝的份上,我不能让它运行。 这是我的引导程序: public class Bootstrapper : Prism.Unity.UnityBootstrapper { //

我目前正在使用Prism 6将我的程序移植到,这是一个WPF应用程序。 所以我安装了Prism.Unity(6.1.1),它与Prism.Wpf(6.1.0)、Prism.Core(6.1.0)、Unity(4.0.1)和CommonServiceLocator(1.3.0)一起提供

然后我带来了那些棱镜样品,但看在上帝的份上,我不能让它运行。 这是我的引导程序:

public class Bootstrapper : Prism.Unity.UnityBootstrapper
{
    /// <exception cref="ActivationException">If there are errors resolving the shell instance.</exception>
    protected override DependencyObject CreateShell()
    {
        return Container.Resolve<Shell>();
    }

    protected override void InitializeShell()
    {
        base.InitializeShell();

        Application.Current.MainWindow = (Window)this.Shell;
        Application.Current.MainWindow.Show();
    }

    protected override void ConfigureContainer()
    {
        base.ConfigureContainer();

        this.RegisterTypeIfMissing(typeof(IWorkRepository), typeof(WorkRepository), true);
    }
}
公共类引导程序:Prism.Unity.UnityBootstrapper
{
///如果解析shell实例时出错。
受保护的覆盖依赖对象CreateShell()
{
返回Container.Resolve();
}
受保护的覆盖无效初始值设置Shell()
{
base.InitializeShell();
Application.Current.MainWindow=(Window)this.Shell;
Application.Current.MainWindow.Show();
}
受保护的覆盖无效配置容器()
{
base.ConfigureContainer();
this.RegisterTypeIfMissing(typeof(IWorkRepository),typeof(WorkRepository),true);
}
}
不幸的是我不能启动它。VS2015说它需要System.Runtime来运行

return Container.Resolve<Shell>();
returncontainer.Resolve();
但是一旦添加,整个类就被标记为错误。如果我直接启动它,就会出现异常,它无法加载Microsoft.Practices.ServiceLocation。 我想知道这种依赖性,因为有几篇文章(包括ms)建议删除所有的实践。*


非常感谢您的帮助,因为我无法让它运行(

您使用的
是什么

整个引导程序可以如此简单(由Prism模板创建):

使用Microsoft.Practices.Unity;
使用棱镜。统一;
使用PrismUnityApp2.视图;
使用System.Windows;
命名空间PrismUnityApp2
{
类引导程序:UnityBootstrapper
{
受保护的覆盖依赖对象CreateShell()
{
返回Container.Resolve();
}
受保护的覆盖无效初始值设置Shell()
{
Application.Current.MainWindow.Show();
}
}
}

System.Runtime
不需要作为参考。可能您无意中使用了其中的名称空间(而不是
Microsoft.Practices.Unity
容器.Resolve
扩展名所在的位置).

好的,我运行了模板,一切正常。但是我需要那些Microsoft.Practices.*.dll吗?其他线程建议删除它们。请查看解决方案中的
文件夹-这些是Unity的程序集,如果您想使用它,最好引用它的程序集;-)但我同意命名可能会产生误导,特别是如果在Prism旁边使用,而Prism的名称中不再有Microsoft.Practices。。。
using Microsoft.Practices.Unity;
using Prism.Unity;
using PrismUnityApp2.Views;
using System.Windows;

namespace PrismUnityApp2
{
    class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void InitializeShell()
        {
            Application.Current.MainWindow.Show();
        }
    }
}