Conditional loading of Modules

Topics: Prism v2 - WPF 3.5
Dec 30, 2009 at 8:53 AM


I am using Prism to build WPF application, where in I have multiple views in my module which needs to be loaded only based on certain conditions, I am using Event Aggregators to switch between views, I am using event aggregators in code behind og my views and using MVVM for all my user controls.

--> Is this approach a good approach for using Event Aggregators to switch between views (defined in a module) in same region?

--> Is there any other better way to subscribe for event aggreagators (I don't want to subscribe in Module class, as this would lead me to strong type my events and that in turn would not allow my Module class (where I initiliaze my modeule) to be disposed off, or correct me if I am wrong?

--> Is there any other way where I could add the modules itself based on consitions at runtime?

Would appreciate any help on the same.



Dec 30, 2009 at 8:37 PM

Hi Suchit,

If all views are defined in the same module, there might be no need to use the EventAggregator, as common .Net events might suffice. This is because there is no need for decoupled communication between the views of a single module. Another possible approach could be using the ScreenCoordinator pattern explained by Ward Bell in these couple of posts:

If you do decide to use the Event Aggregator, the only way Prism provides to subscribe to events is explained here.

To add modules based on conditions at runtime, an approach that could be used is having all the conditional modules load on demand and load only those modules after your conditions have been determined. Some threads that discuss this are the following:

Please let me know if this helps.

Damian Schenkelman


Dec 31, 2009 at 4:11 AM

Thanks  very much Damian, these posts were of great help and gave a lot of solutions that I was looking for.

One more question, rather taking your point of view,

In my application the modules which I am loading on demand, is their any way I could unload those modules also at runtime, to add to it (only if unloading is also possible), these modules might be used frequently in a running instance of my application, so again would this idea of loading/unloading be very expensive if the frequency of usage is high for modules which are loaded on demand?