Get list of interfaces and types from a loaded Module

Topics: Prism v1
Mar 1, 2009 at 1:07 PM
Is there a way to query the Module to determine the various public types? We want to dynamically load a view (there are dozens) based on a menu click. I am able to dynamically load the module and next want to get a hold of the list of presenters in the module to check if the one the user has asked for exists and load it into the proper region.

Here is a pseudocode example of what I am looking to do:

string moduleName = String.Format("{0}Module", viewSelected.ModuleName);_moduleLoader.Initialize(new ModuleInfo[] { _moduleEnumerator.GetModule(moduleName) });string typeName = String.Format("I{0}Presenter", viewSelected.ViewName);Type myType = GetTypeFromName(typeName); <-- This
Mar 4, 2009 at 3:45 PM
Technically speaking, yes you can do what you are describing. You can use reflection to get the assembly the module comes from and then load all the classes from that assembly that the module is defined in.

I don't really recommend doing that though. I would recommend creating a seperate registration piece. Each module can register it's views in such a way that your menu's can find them.

Maybe this blogpost helps you. In this post, i'm showing how to build an outlook style app. I have a list of buttons (the outlook navigation buttons) Each module can contribute items for those buttons. Only when you click the button do I want to create the views and add them to the regions.

Let me know if that's helpful.
Mar 6, 2009 at 5:02 PM



This is possible by doing:

Type myType = Type.GetType(typeName);  //where typeName is the assembly qualified name for the type.

((IBasePresenter)_container.Resolve(myType)).View  //you cannot use generics, because you don’t know the type at compile-time, so you will need a known interface to get the View from (like IBasePresenter).


In most containers (including Unity) you can even use strings as keys apart from types for these kind of things:



For that to work, you need to register the presenter with a string key and the IBasePresenter interface in the module’s initializer:

_container.RegisterType<IBasePresenter, ConcretePresenterType>(“myViewName”);


Another way to implement what you want is using the EventAggregator service. You could have your on demand modules subscribed to an event in the EventAggregator to show a view based on the name that the subscriber gets from the EventArgs. Then, in the Click handler you would initialize the module (which will really be initialized only the first time), and later publish that same event in the EventAggregator, passing the view name as an argument. In this way, you can host the name resolution to a specific view type in the on demand module making your modules less coupled, and also, using this approach, you will be able to avoid using the GetType method to resolve types.

Check the following sample code to see a possible implementation of this:


//In the menu click handler…

private void MenuItem_Click(object sender, RoutedEventArgs e)


    string moduleName = String.Format("{0}Module", viewSelected.ModuleName);


    _moduleLoader.Initialize(new ModuleInfo[] { _moduleEnumerator.GetModule(moduleName) });


    ActivateModuleEvent activateModuleEvent = this.eventAggregator.GetEvent<ActivateModuleEvent>();




//In the ModuleInitializer of the Module loaded on demand…

private readonly IRegionManager _regionManager;

private readonly IUnityContainer _container;


public ModuleInitializer (IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer container)


    _regionManager = regionManager;

    _container = container;

    eventAggregator.GetEvent<ActivateModuleEvent>().Subscribe(ActiveModuleEventHandler, ThreadOption.UIThread, true);



public void ActiveModuleEventHandler(string viewName)


    switch (viewName)


    case "ViewA":








Perhaps you could find useful the following articles about loosely coupled communication mechanism in the documentation:

·         Event Aggregator service to publish and subscribe to events.

·         Commands that allow to handle user interface (UI) actions to bind the UI to the logic that performs the action.


Please let me know if this helps.


Ezequiel Sculli