On demand module initialization

Aug 26, 2008 at 10:50 AM
I create a sitemap type module.  On first click on a module the module is initialized on demand. However, some the user close the tab where the new view is displayed. I can't reopen the view.  Is there a way once a module is loaded to force the module to reinitialized.  I need a way to show the view from the on demand loaded module once it's was closed.
Aug 28, 2008 at 5:31 AM
Initializing a module twice isn't exactly safe, as most of the stuff that is in the initialize method of the module is common for all the components in the module. Initializing the module again could give you serious problems.
You will need quite a construction to solve these issues.

There is another way to approach this problem. You can create a View menu item and configure as a region. Once a module initializes it could add a menuitem to that menu and attach a Show...View command to it.
Inside the commandhandler you can check if the view that belongs to the module is still visible and show it if it isn't (The user closed the tabitem). This is a pretty elegant way to make it possible to reload a view after it has been closed.
Sep 2, 2008 at 12:33 AM
martalex,

I agree with WMeints. Your module can still load on demand, but it should really only manage the requests of views as oppsed to only displaying a view upon initialization. I would encapsulate the logic to display your view and implement some access to request a view from this module, like WMeints mentioned. Your module can then resolve a new instance and place it in a region. I would also ensure that your module handles the teardown off these views when a request to close a view is invoked.
 
Just adding my 2 cents,

Andres Olivares
Sep 2, 2008 at 10:56 PM
I implements something like WMeints recommended but instead of being a menu item I created a collection of command since I don't need a menu.  It works fine.  The only think I notices is that removing a view from a region does not dispose the view so on the next load the previous instance is used.  So not sure what Andres Olivares is talking about when he says to handle the teardown off these views.
Sep 3, 2008 at 2:39 PM
martalex,

If you created the view through object resolution:

container.Resolve<MyViewType>();

you should dispose of the view throught the container as well:

container.Teardown(MyViewInstance).

Andres Olivares