Prism中这两种加载模块的方式有什么区别?

发布于 2024-07-26 20:09:19 字数 1242 浏览 2 评论 0原文

之间的区别

protected override void InitializeModules()
{
    IModule customerModule = Container.Resolve<CustomerModule.CustomerModule>();
    IModule helloWorldModule = Container.Resolve<HelloWorldModule.HelloWorldModule>();

    customerModule.Initialize();
    helloWorldModule.Initialize();
}

谁能解释一下在 Prism 中加载模块的这种方式这种方式

protected override IModuleCatalog GetModuleCatalog()
{
    ModuleCatalog catalog = new ModuleCatalog()
        .AddModule(typeof(CustomerModule.CustomerModule))
        .AddModule(typeof(HelloWorldModule.HelloWorldModule));
    return catalog;
}

:我在演示中看到了这两种方式,但据我所知,它们是这样做的同样的事情,两者似乎都传递了我在模块中需要的容器和regionManager:

public class CustomerModule : IModule
{
    public IUnityContainer Container { get; set; }
    public IRegionManager RegionManager { get; set; }

    public CustomerModule(IUnityContainer container, IRegionManager regionManager)
    {
        Container = container;
        RegionManager = regionManager;
    }

    public void Initialize()
    {
        RegionManager.RegisterViewWithRegion("MainRegion", typeof(Views.CustomerView));
    }

}

Can anyone explain the difference between this way of loading modules in Prism:

protected override void InitializeModules()
{
    IModule customerModule = Container.Resolve<CustomerModule.CustomerModule>();
    IModule helloWorldModule = Container.Resolve<HelloWorldModule.HelloWorldModule>();

    customerModule.Initialize();
    helloWorldModule.Initialize();
}

and this way:

protected override IModuleCatalog GetModuleCatalog()
{
    ModuleCatalog catalog = new ModuleCatalog()
        .AddModule(typeof(CustomerModule.CustomerModule))
        .AddModule(typeof(HelloWorldModule.HelloWorldModule));
    return catalog;
}

I've seen both ways in demos but as far as I can tell they do the same thing, both seem to pass in a container and regionManager that I need in my modules:

public class CustomerModule : IModule
{
    public IUnityContainer Container { get; set; }
    public IRegionManager RegionManager { get; set; }

    public CustomerModule(IUnityContainer container, IRegionManager regionManager)
    {
        Container = container;
        RegionManager = regionManager;
    }

    public void Initialize()
    {
        RegionManager.RegisterViewWithRegion("MainRegion", typeof(Views.CustomerView));
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一世旳自豪 2024-08-02 20:09:19

IModuleCatalog GetModuleCatalog() 和 InitializeModules 都来自 UnityBootstrapper。

  • GetModuleCatalog 用于配置加载模块的方式。 InitializeModules 用于初始化模块。

  • GetModulecatalog 将在调用初始化模块之前被触发。

  • 在大多数情况下,您不需要覆盖InitializeModules,但您需要告诉UnityBootstrapper您希望如何加载模块(基于app.config、目录查找或Xap动态加载器等)< /p>

希望它有助于。

Both IModuleCatalog GetModuleCatalog() and InitializeModules are from UnityBootstrapper.

  • GetModuleCatalog is for configuring how you want to load the module. And InitializeModules is for initializing the module.

  • GetModulecatalog will be fired before calling Initializing the module.

  • You don't need to override the InitializeModules for the most of scenarios but you will need to tell the UnityBootstrapper how you want your modules to be loaded (based on app.config, Directory Lookup or Xap Dynamic Loader or etc)

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文