views:

414

answers:

3

I need to make sure certain essential data are loaded before a module is loaded and shown on screen. considering the async nature of data loading in silverlight, I was wondering if there is a pattern I should follow to load my data (like an event on the module or the bootstrap to hook into, or a method to override)...

+1  A: 

you can set module InitializationMode to OnDemand and once you have your data call moduleManager.LoadModule("YourModuleName"); as described here.

jarek
This way I have to make every single module "load on demand" because all of them rely on ref data...
Ali Shafai
A: 

There's another alternative as well. If you know you're going to need the module, and the data is statically stored inside another module, you can establish dependencies:

ModuleCatalog m = new ModuleCatalog();
...
m.AddModule(typeof(PersonModule.PersonModule), "ModuleA");

In this scenario, your module in question would establish a dependency on whatever module has the data, and this would ensure that the data is loaded before-hand.

Erik Mork
I will still have the same problem. how do I ensure that the module with ref data is loaded after the ref data?ref data loading is async, so there is no guaranty by the time the "module" is loaded, the "data" is loaded too.
Ali Shafai
A: 

I am having a heckuva time trying to load modules on demand using Prism 2. Has anyone succeeded in doing this?

I have two regions; left and right (like outlook). I have an infragistics outlook control in the shell. I press an outlook group button and it executes a command to load the selected module.

The selected module has two views; one view goes in the region I specify in the Outlook group container, into a region already named, and the other view goes into the content pane. The theory is to click on another Outlook group button and change the content region view (the right region).

My bootstrapper has this:

return new DirectoryModuleCatalog() { ModulePath = @"N:\StarfishModules" };

This is my first module called Visit Schedule:

Imports Microsoft.Practices.Composite.Modularity
Imports Microsoft.Practices.Composite.Regions
Imports Cefas.Starfish.Infrastructure

<Microsoft.Practices.Composite.Modularity.Module(ModuleName:="VisitScheduleModule", OnDemand:=True)> _
Public Class VisitScheduleModule
    Implements IModule

    Private mobjRegionManager As IRegionManager

    Public Sub New(ByVal objRegionManager As IRegionManager)
        mobjRegionManager = objRegionManager
    End Sub

    Public Sub Initialize() Implements IModule.Initialize
        'the following methods use View First composition 
        mobjRegionManager.RegisterViewWithRegion(RegionNames.MainRegion, GetType(VisitScheduleDayList))
        mobjRegionManager.RegisterViewWithRegion(RegionNames.VisitScheduleDaySelectRegion, GetType(VisitScheduleDaySelect))
    End Sub
End Class

It has two views as you can see, one to select a date, the other to display data.

When I click on the outlook button for this module, it loads both views and I can click the calendar and get my data.

I have a second module called Model Module that just loads one view into the main content region. I press the button for it and step through the code and I watch it load and I watch the view get activated but nothing shows in the content region. All that view has on it is a label and a button; it doesn't load data or do anything.

I then click the outlook group for the Visit Schedule and nothing is loaded in the content region. The outlook region is fine but that's because the calendar loaded in its own region and didn't get removed or replaced. Each outlook button has its own region.

The command handler has this code:

            RemoveViews(); //this method cycles through any views in the Content region and removes them

            switch (SelectedGroupHeader)
            {
                case "Visit Schedule":
                    this.moduleManager.LoadModule("VisitScheduleModule");
                    break;
                case "Model Module":
                    // Get main region
                    this.moduleManager.LoadModule("WPFModule1");
                    break;
                default:
                    SelectedView = "";
                    break;
            }

Can someone tell me what I'm doing wrong? Much appreciated...

Richard Golko
You should ask this as a new question, not post it as an answer. The "Ask Question" button is in the top right of the page.
sth