AllModulesLoaded Event

Topics: Prism v4 - WPF 4
Dec 20, 2010 at 1:25 PM
Edited Dec 20, 2010 at 2:25 PM

What is the best way to know that all modules are loaded?

Would something like this work?

ModuleManager

- List of modules with Initialized flag set to false

Module

- After Initialization sends a global command or raises a event that it is initialized

ModuleManager

- Once all module Initialitzed flags are true we we know that all modules are loaded.

 

Developer
Dec 20, 2010 at 3:26 PM

Hi,

The approach you're mentioning seems a valid one to determine when all the modules are loaded. You might also find more information on the subject in the Modularity Quickstarts (for which there is a MEF version and a Unity one as well).

Thanks for sharing your insight with the community, and I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Dec 20, 2010 at 3:37 PM

Hi Guido,

I am still looking at different approaches.

I am surprised no one needed this event till now.

I am even considering implementing a IObserver interface for the ModuleManager and IObservable interface for the modules.

Do you know where I can hook into the Initialization of a module when it is complete? (ModuleInfo.State = Initialized)

Cheers,

Ranjith

Dec 20, 2010 at 3:45 PM

Too quick, thanks for pointing me to the Modularity QuickStart.

I think they have something I could reuse :)

Developer
Dec 20, 2010 at 4:02 PM
Edited Dec 20, 2010 at 4:03 PM

Hi Ranjith,

I'm glad you can reuse components from the Modularity QuickStart. As it is shown in the QuickStart, there is a LoadModuleCompleted event in the IModuleManager interface that you can subscribe to, in order to determine when a module has been loaded.

Also, the subject has been discussed in the following threads, but for Prism v2. Prism v4 has introduced changes in the way modules are managed. You can read more about it in this chapter from the MSDN documentation.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Dec 21, 2010 at 8:31 AM

Hi Guido,

I was looking into the Modularity Quickstart.

It has a Module Tracker with its own State variables in the class "ModuleInitializationStatus".

Why are the State variables in ModuleInfo.State not used? 

Are the PRISM inbuilt State variables updated after the Module.Initialize function is called? 

Cheers,

Ranjith

Developer
Dec 21, 2010 at 3:57 PM
Edited Dec 21, 2010 at 3:58 PM

Hi Ranjith,

The ModuleInitializationStatus is the enumeration used for tracking a modules's state in the ModuleTracker class for the QuickStart. From the documentation, "This QuickStart has additional classes that help to track module initialization state. These classes are for demonstration purposes only and are not intended for shipping applications. The Shell user interface contains a ModuleControl for each module. The Shell also has the ModuleTracker class as its DataContext. The ModuleTracker contains a ModuleTrackingState for each module. ModuleControl data binds to ModuleTrackingState and uses a custom style to visually display the downloading and initialized state of the module."

The QuickStart uses the ModuleInitializationStatus to fulfill its scenario (for example, that enumeration contains a Downloading state that is not present in ModuleInfo.State), but you could use whichever mechanism you need (including the ModuleInfo.State property) to track the state of your modules.

As for your last question, even when using a custom mechanism to track the Module's initialization status, the ones in the ModuleInfo.State are also updated.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi