感兴趣的 Prism 模块的功能 类 (Xamarin Foirms + Prism)

Functionality of Prism modules in interested classes (Xamarin Foirms + Prism)

美好的一天!


更新

我不明白如何使用模块逻辑从 class 访问 Prism 模块的功能。

问题:

谢谢大家的回答! 祝你今天过得愉快! /对不起 google 翻译/

棱镜应用程序的模块用于模块化代码库。它们与视图或视图模型无关,而是将应用程序拆分为可以独立开发、测试和替换的组件。如何拆分应用程序取决于您。

也许您应该查看 documentation chapter about modularity...

编辑:关于具体问题:

How do I get access to the implementation of the IServiceA functionality (defined in the module) in PageAViewModel, which I forget to do?

您创建类型为IService的构造函数参数,Prism将为您提供已注册的实现:

internal class PageAViewModel
{
    public PageAViewModel( IService service )
    {
        service.DoStuff();
    }
}

How can I manage the life of ModuleA / ServiceA if I want to use this functionality on a number of different countries, without loading the module every time

您不能也不需要管理 ModuleA 的生命周期,Prism 会负责。至于,ServiceA你注册的时候选择了一辈子:

  • containerRegistry.Register<IService, ServiceA>() 为每个页面创建一个新的服务实例
  • containerRegistry.RegisterSingleton<IService, ServiceA>() 为所有页面创建一个服务实例