Vegi Woo
Vegi Woo

Reputation: 65

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

Good day!


UPDATE

I don’t understand how to access the functionality of the Prism module from the class using the module logic.

Questions:

Thank you all for any answers! Have a nice day! /Sorry for google translate/

Logic

Upvotes: 0

Views: 156

Answers (1)

Haukinger
Haukinger

Reputation: 10863

The modules of a prism application are for modularizing the code base. They have nothing to do with views or view models, but rather splitting the application up into components that can be independently developed and tested and replaced. How you split your application is up to you.

Probably you should review the documentation chapter about modularity...

Edit: about the concret questions:

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

You create a constructor parameter of type IService and prism will provide you with the registered implementation:

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

You cannot and need not manage the lifetime of ModuleA, prism takes care of that. As for, ServiceA you chose a lifetime when registering:

  • containerRegistry.Register<IService, ServiceA>() creates a new service instance for each page
  • containerRegistry.RegisterSingleton<IService, ServiceA>() create a single service instance for all the pages

Upvotes: 1

Related Questions