Modules loaded

Topics: Prism v4 - WPF 4
Jul 19, 2011 at 8:15 PM

How do I get a Collection with all modules loaded in my application?

Jul 20, 2011 at 2:14 PM


As explained on this thread, you could have a custom service hold a collection of loaded modules; that service could subscribe to the ModuleManager.LoadModuleCompleted event, and could use the ModuleCatalog.Modules property to have a notion of the total modules present in the catalog.

I hope you find this helpful.

Guido Leandro Maliandi

Jul 20, 2011 at 3:18 PM

Thank you. I'll try to implement something like that.

Sorry for my bad English.

Jul 20, 2011 at 3:20 PM

Once you have your service implemented, it would be helpful if you could post it here, so that other users from the community can benefit from it, and also review and suggest improvements for your implementation.


Guido Leandro Maliandi

Jul 20, 2011 at 3:51 PM

This service ... would be another project (application) to communicate with my application, right? I am doing a menu that will be assembled programmatically. ModuleCatalog had seen, but can not get the instance with the modules that were loaded, the service was going to do that, right? But there is no way to do this with static class?

I'm scheduling based on samples and documentation.

Jul 20, 2011 at 4:00 PM
Edited Jul 20, 2011 at 4:01 PM


The service could be simply a class that provides that functionality. A common practice for doing so is to provide an interface for your service in an infrastructure project (one that is referenced throughout the different projects in your solution), and provide the implementation for that service in a specific project you consider appropriate (i.e. a module, or the shell project, as you find it better); then register an interface mapping using Unity/MEF between the interface and the corresponding implementation. Therefore, the service will be shared, but the modules will not necessarily have a reference to the project that contains the implementation. That is a benefit over using a static class; and also, using a shared service improves testability (as you can mock that service in a test scenario) over using a static class (which can't be mocked).

You can read more about shared services in this section of the Communication Chapter of the Prism MSDN documentation. Also, you can find an example of the usage of shared services in the Stock Trader Reference Implementation (where the INewsFeedService is an example of a shared service interface, with the implementation being provided in the NewsFeedService class placed in the StockTraderRI.Modules.News module, and exported via MEF using the interface as the contract type).

I hope you find this helpful.

Guido Leandro Maliandi