Lazy Loading Modules

Topics: CAB & Smart Client Software Factory
May 9, 2006 at 10:17 AM
originally posted by: dmateer

Newbie question:

I'm just now being introduced to the CAB. So far, I'm seeing some great potential. One thing I can't seem to get my head around, however, is the module loading process. It seems like the ModuleLoaderService takes all the modules found in the IModuleEnumerator implementation and unconditionally loads them as part of the entire application startup. If one wanted to lazy load the modules, does this require a custom implementation of the IModuleLoaderService, or can this be controlled in the default ModuleLoaderService implementation? I'm forseeing some unreasonable startup time and memory drains if all modules must be loaded, some of which may involve some significant initialization logic.

Thanks for your help!
May 9, 2006 at 7:37 PM
originally posted by: GregShaw

Good question. I struggled with this one as well in the beginning.

Have a look at ProfileCatalog.xml. In it you can specify roles so that modules
are loaded based on the role that the user is in. The May 8 drop includes a form
where you can select the role for the user and this will load different modules that match the selected role.

HTH, Greg.
May 10, 2006 at 3:54 AM
originally posted by: dmateer

Thank you very much for the reply. Can you point me in the right direction on how the ProfileCatalog.xml needs to be structured to enable this? I've gone through the documentation a few times and can't seem to figure it out. (Again, I'm a newbie, so I'm probably just missing something.) Here's an example of what I am trying to do:

Suppose I have user Andy, who has rights to all the modules in my application, but I know from our business processes that 95% of the time he only uses ModuleA during a session. However, the application has six modules which he could potentially use during a session. That is, he is in the role for all six modules, but 95% of the time the CPU time will be wasted loading the other modules.

Can the CAB ONLY load ModuleA during the initialization phase, and then load ModuleB, for example, only after he clicks on, say, a menu option that requires ModuleB?
May 13, 2006 at 8:55 PM
originally posted by: GregShaw

I actually don't remember how I worked out the following structure:
<ModuleInfo AssemblyFile="xys.dll">
<Role Allow="Staff" />
But the above only loads the xyz.dll if the user is in the "Staff" role.
Check out the following for loading modules on demand. I haven't read it in detail but matias
tends to write some really good and useful stuff.