Loading Modules from a directory and specifying initializationmode

Topics: Prism v2 - WPF 3.5
Apr 23, 2009 at 3:37 PM
Hi, I'm new to Prism2 and i'm trying to create an app that loads modules from the directory. I'm trying to figure out how to place an attribute of the module to indicate that InitializationMode=WhenAvailable, reason being "DesktopModule" is a module that is OnDemand.

[

Module (ModuleName="AdditionalApp")]
[
ModuleDependency("DesktopModule")]
public class AdditionalAppModule :IModule

 

{
// some code here
}

Will appreciate your help.

thanks!
j

Apr 23, 2009 at 6:46 PM

Hi J,

 

If the DesktopModule is loaded OnDemand, and the AdditionalAppModule depends on the DesktopModule I assume you are using code like this in the DesktopModule:

[Module (ModuleName="DesktopModule", OnDemand = true)]
public class DesktopModule :IModule

{
// some code here
}

What you will have to do is mark the AdditionalApp module as OnDemand loaded. This is because it depends on a module that is loaded on demand:

[Module (ModuleName="AdditionalApp", OnDemand = true)]
[ModuleDependency("DesktopModule")]
public class AdditionalAppModule :IModule

{
// some code here
}

I believe you are trying to set InitializationMode=WhenAvailable because that is the exception message thrown if you do not mark the AdditionalApp module as OnDemand. But on the Directory Lookup scenario it is similar to using the OnDemand attribute.

 

Now depending on what your application does you have two options:

 

1.       If you load the AdditionalApp module directly, the DesktopModule will automatically be loaded before it, since you have established a dependency.

2.       If you load the DesktopModule you will have to load the AdditionalApp in the DesktopModule initializer.

 

Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman

Apr 24, 2009 at 1:54 AM
Thanks for the reply Damian.

This is my scenario and what i want to achieve:

- I have a DesktopModule that is being loaded onDemand.
- DesktopModule contains a region of several applications  links
- what i want is to set up my project so that future module developers can just dump a DLL and a folder and that module containing a view that automatically registers with the DesktopModule region will allow it to show up without recompiling the main app.

I guess my question is, is there a way to load the modules in DesktopModule initializer from directory as well?

thanks and regards,
J

Apr 24, 2009 at 9:12 PM

Hi J,

 

If I understand correctly you want to be able to load the modules that depend on DesktopModule automatically, once that module is loaded on demand.

I have created a blog post that addresses this scenario, so you might find it useful.

 

Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman