感兴趣的 Prism 模块的功能 类 (Xamarin Foirms + Prism)
Functionality of Prism modules in interested classes (Xamarin Foirms + Prism)
美好的一天!
更新
我不明白如何使用模块逻辑从 class 访问 Prism 模块的功能。
问题:
如何访问我忘记执行的 PageAViewModel 中的 IServiceA 功能(在模块中定义)的实现?
如果我想在多个不同的国家/地区使用此功能,而不是每次都加载模块,我该如何管理 ModuleA / ServiceA 的生命周期(场景 - 我在加载时调用 ModuleA / ServiceA一个应用程序,在PageA / PageB / PageC上使用它,使用后我卸载它).
谢谢大家的回答!
祝你今天过得愉快!
/对不起 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>()
为所有页面创建一个服务实例
美好的一天!
更新
我不明白如何使用模块逻辑从 class 访问 Prism 模块的功能。
问题:
如何访问我忘记执行的 PageAViewModel 中的 IServiceA 功能(在模块中定义)的实现?
如果我想在多个不同的国家/地区使用此功能,而不是每次都加载模块,我该如何管理 ModuleA / ServiceA 的生命周期(场景 - 我在加载时调用 ModuleA / ServiceA一个应用程序,在PageA / PageB / PageC上使用它,使用后我卸载它).
谢谢大家的回答! 祝你今天过得愉快! /对不起 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>()
为所有页面创建一个服务实例