Loading module more times

Topics: Prism v2 - WPF 3.5
Jun 10, 2009 at 11:16 AM


I'm writing a WPF Application using PRISM v2 and AvalonDock in order to have several views.

Each view contains a module (that the application loads at run-time by ModuleManager.LoadModule(ModuleName)).

The user could be open the same view more times (for example to work on more things at the same time) but this is a problem for me because the loaded modules cannot be re-loaded.

Is there a way to do this thing?




Jun 10, 2009 at 6:00 PM

This question comes up a good bit. For me, the key was in understanding that what you are interested in doing is not reloading the module - you are actually interested in instantiating another instance of a view from that module. Once that module is loaded, it does not need to be loaded again - you now have access to the views it contains and can create multiple instances of them at will.

In my case, I have several modules that should display a list of records based on a user selection. I created a module for that record list and reference it in any module that needs to display that view and then inject the view after the user takes the required action. Check out the View Injection QuickStart for an example - the Employees Controller is a great start.

I accepted the need to reference the record list module in my other modules for ease of implementation. I eventually would like to revisit it and see if there is a reasonable way to decouple that, but the issue is that for ViewInjection to work as it does in the QuickStart, the module injecting the view needs to be aware of the view type it is injecting. Again, I can live with that (for now at least).

Rock on.


Jun 16, 2009 at 8:11 PM
Edited Jun 16, 2009 at 8:11 PM

Any diea how you would do it if you actually had to create new instances of the same modules though? Views, Data, State all the works.

Jun 17, 2009 at 6:03 PM

I think the basic concept still holds - you are still not creating whole new instances of the module. You are creating new instances of a view and (maybe here's the key) its data context.


In the scenario I described above, I am actually creating presenters first, each one managing it's own view. That means multiple data contexts, and with the help of some state management plumbing and view naming, my app could remember those context/view pairs for the future. I can also imagine storing the state of the region manager in relation to those pairs so you could recreate them in the same location in the shell, for example, or at the same size, with the same template, etc. Referencing my scenario again, I use WCF, SQL Server and serialization to store snapshots of the form states that generate my reports. This could be extended to storing a snapshot of the shell's state, or the region manager's state, or whatever...


Apologies if I have misunderstood your question. If there is a specific scenario that you cannot see covered by this idea, describe it and we'll go from there.


Rock on.

Jun 17, 2009 at 7:26 PM

Hi Arch,


The following thread deals with a similar scenario. Perhaps you can find it useful:

·         Confirmation of understanding


Please let me know if this helps.


Damian Schenkelman


Jun 17, 2009 at 8:46 PM

Thanks guys, yes I think both the responses are useful. Essentialy, load a single module and create instances of the views (et all). That's a good start.