3
votes

Just starting out with Prism and relying on the MSDN documentation to teach me - there's paragraphs in particular that confuse me right now, on the subject of Modules

"After a module is loaded and initialized, the module assembly cannot be unloaded because the module instance reference will not be held by Prism therefore the module class instance may be garbage collected after initialization is complete"

and

"Module instance lifetime is short-lived by default – after Initialize is called, the reference to the module is released. If you do not manually establish a strong reference chain to the module instance, it will be garbage collected"

I'm a little confused by this - what is the implication of this?

Is the IModule-derived class the actual implementation of your class library or is it just the metadata class that is responsible for Prism loading your actual class library, and once your assembly is loaded into the AppDomain, you can call code from it anytime?

I'm confused - right now, my take-away from those two paragraphs is that modules need to be re-instantiated everytime they're used throughout the Prism application?

1

1 Answers

3
votes

The class that derives from IModule should contain the one-time initialization code, like registering views with regions. When you load the module, an instance of the IModule derived class is created, the Initialize method is called, and then the module is considered loaded. The instance of the IModule derived class is lost after initialization, but the module is still accessible.

Bottom Line: No, the module does not have to be re-loaded/initialized every time you use it. It is only loaded/initialized once and then it should be all set up.