Load type on demand

Topics: Prism v4 - WPF 4
Aug 23, 2011 at 7:55 AM


my application will have many modules, which I want to load on demand.
The shell will have a menu on the left side. Selecting a menu item will load the related view in the content area on right side.

First, I would associate menu item to view name.
So when the user click "Customers" item, I could compose/resolve "CustomersView" and show it in content area.
But I cant compose objects from modules which are not already in memory.

AFAIK there's not a built in way to say "compose/resolve this type. If you can't find it load it from "module1.dll" ".
Is this correct? 

So I have to do it by myself, something like:

  1. Check if requested view class exists. If so goto point 3
  2. Else load the module which contains it (using a view=module dictionary built at design time)
  3. Compose/resolve class

What do you think about?





Aug 23, 2011 at 9:26 PM

Hi Corrado,

The main counterpart of the approach that you proposed is that it doesn't achieve loose coupling between the components because the main project have not only to know the modules beforehand, but also know the views and in which modules they are.

Another possible approach to do this is to communicate between the modules to show the views.

The main project could know that certain actions performed by the user (for example, clicking the Customers menu item) should be resolved by certain modules (for example, the module containing the CustomersView) and load them on demand.

Then, when the action is performed, you should do the following:

  1. Check if the module has been loaded or not and, if it hasn’t, load it.
  2. Then, communicate to the module using something like an event through the event aggregator or using a shared service to request the module to show the view.

This way the module shows its view in the region, and the main project doesn’t have to know the view but the module only.

For more information about this you can check:

I hope you find this useful,

Damian Cherubini