C# prism配置容器用于什么

C# prism配置容器用于什么,c#,wpf,unity-container,prism,C#,Wpf,Unity Container,Prism,我正在阅读微软的棱镜图书馆。我只是不明白ConfigureContainer() shell应用程序中的代码如下所示: internal class JamSoftBootstrapper : UnityBootstrapper { protected override IModuleEnumerator GetModuleEnumerator() { return new DirectoryLookupModuleEnumera

我正在阅读微软的棱镜图书馆。我只是不明白
ConfigureContainer()
shell应用程序中的代码如下所示:

 internal class JamSoftBootstrapper : UnityBootstrapper
    {
        protected override IModuleEnumerator GetModuleEnumerator()
        {
            return new DirectoryLookupModuleEnumerator("Modules");
        }

        protected override void ConfigureContainer()
        {
            Container.RegisterType<IShellView, Shell>();

            base.ConfigureContainer();
        }

        protected override DependencyObject CreateShell()
        {
            ShellPresenter presenter = Container.Resolve<ShellPresenter>();
            IShellView view = presenter.View;
            view.ShowView();
            return view as DependencyObject;
        }
    }

    public interface IShellView
    {
        void ShowView();
    }

    public class ShellPresenter
    {
        public IShellView View { get; private set; }

        public ShellPresenter(IShellView view)
        {
           View = view;
        }
    }
内部类jamsoftwootstrapper:UnityBootstrapper
{
受保护的重写IModuleEnumerator GetModuleEnumerator()
{
返回新的DirectoryLookupModuleNumerator(“模块”);
}
受保护的覆盖无效配置容器()
{
Container.RegisterType();
base.ConfigureContainer();
}
受保护的覆盖依赖对象CreateShell()
{
ShellPresenter=Container.Resolve();
IShellView视图=presenter.view;
view.ShowView();
返回视图作为DependencyObject;
}
}
公共界面IShellView
{
void ShowView();
}
公开课主持人
{
公共IShellView视图{get;private set;}
公共ShellPresenter(IShellView)
{
视图=视图;
}
}

我想了解为什么在ConfigureContainer()中注册IShellView、Shell。sceens背后发生了什么?

UnityBootTrapper
由PRISM内部提供,用于解决注册对象的依赖关系。您可以像在示例中一样使用它配置自定义对象


在示例中,您向实例IShellView注册了Shell

Container.RegisterType<IShellView, Shell>();
Container.RegisterType();
所以,每当您要求容器为IShellView获取对象时,它都会给您一个Shell对象的实例

IShellView shellObject = Container.Resolve<IShellView>();
IShellView shellObject=Container.Resolve();
因此,
ConfigureContainer
为您提供了向其容器注册对象的支持


引自链接:

配置IUnityContainer。可能在派生类中被覆盖 添加应用程序所需的特定类型映射


此外,您可以在此处阅读更多信息-。

UnityBootTrapper
由PRISM内部提供,用于解决注册对象的依赖关系。您可以像在示例中一样使用它配置自定义对象


在示例中,您向实例IShellView注册了Shell

Container.RegisterType<IShellView, Shell>();
Container.RegisterType();
所以,每当您要求容器为IShellView获取对象时,它都会给您一个Shell对象的实例

IShellView shellObject = Container.Resolve<IShellView>();
IShellView shellObject=Container.Resolve();
因此,
ConfigureContainer
为您提供了向其容器注册对象的支持


引自链接:

配置IUnityContainer。可能在派生类中被覆盖 添加应用程序所需的特定类型映射


此外,您可以在此处阅读更多信息-。

UnityBootTrapper
由PRISM内部提供,用于解决注册对象的依赖关系。您可以像在示例中一样使用它配置自定义对象


在示例中,您向实例IShellView注册了Shell

Container.RegisterType<IShellView, Shell>();
Container.RegisterType();
所以,每当您要求容器为IShellView获取对象时,它都会给您一个Shell对象的实例

IShellView shellObject = Container.Resolve<IShellView>();
IShellView shellObject=Container.Resolve();
因此,
ConfigureContainer
为您提供了向其容器注册对象的支持


引自链接:

配置IUnityContainer。可能在派生类中被覆盖 添加应用程序所需的特定类型映射


此外,您可以在此处阅读更多信息-。

UnityBootTrapper
由PRISM内部提供,用于解决注册对象的依赖关系。您可以像在示例中一样使用它配置自定义对象


在示例中,您向实例IShellView注册了Shell

Container.RegisterType<IShellView, Shell>();
Container.RegisterType();
所以,每当您要求容器为IShellView获取对象时,它都会给您一个Shell对象的实例

IShellView shellObject = Container.Resolve<IShellView>();
IShellView shellObject=Container.Resolve();
因此,
ConfigureContainer
为您提供了向其容器注册对象的支持


引自链接:

配置IUnityContainer。可能在派生类中被覆盖 添加应用程序所需的特定类型映射


另外,您可以在这里阅读更多信息-。

我注册给您的答案是:)
ConfigureContainer
只是抽象类
UnityBootTrapper
中的方法,您可以在其中注册所有
Prism
服务(
ModuleManager
RegionManager
EventAggregator
)。您可以创建自定义的
引导程序
类,从中可以管理依赖关系。在您的情况下,每次在代码中请求
IShellView
,都会得到
Shell
的实例


我推荐你。这是免费的。

我已经注册,给你答案:)
ConfigureContainer
只是抽象类
UnityBootTrapper
中的方法,您可以在其中注册所有
Prism
服务(
ModuleManager
RegionManager
EventAggregator
)。您可以创建自定义的
引导程序
类,从中可以管理依赖关系。在您的情况下,每次在代码中请求
IShellView
,都会得到
Shell
的实例


我推荐你。这是免费的。

我已经注册,给你答案:)<代码>配置容器