ModuleDependency hard reference with a string

Topics: Prism v4 - WPF 4
Jul 27, 2012 at 8:25 AM
Edited Jul 27, 2012 at 8:26 AM


In my MEF application I have module dependencies, but the ModuleDependency tag uses a string to reference another module. Is there a way of using it with a syntax that accepts a type, like:


Or any other ideas on how to do this type of injection or ensure that the dependent module is loaded? Wuold it be possible to include it in the next version of MEF? It would be great!!!

Thanks very much,


Jul 27, 2012 at 7:23 PM


As far as I know Prism does not provide an approach for resolving module dependencies defined through the type of a custom interface.

By default, when specifying dependencies in code when using MEF, the current implementation of the ModuleExport attribute only allows getting or setting the contract names of modules that your module will depend upon.

For example this attribute could be used like this:

[ModuleExport(typeof(ModuleA), DependsOnModuleNames = new string[] { "ModuleD" })]
public class ModuleA : IModule

Also, based on my understanding, Prism uses this modules' contract name to identify the modules that needs to retrieve or load, and the dependencies of each modules. This can be seen in the current implementations of the MefModuleManager and ModuleCatalog classes.

Take into account that Prism provides extensibility points for developers that can be used to tailor the library to suit their needs. For more information and guidelines about this, you could check the following appendix of the Prism documentation:

On the other hand, in my opinion, you could benefit from other approaches provided by Prism to register your modules, like registering them in a configuration file or in a XAML module catalog. Using these approaches you can define modules and their dependencies in a loosely coupled pattern (without even needing to have a reference to the modules). If you are interested, you could find more information regarding the different approaches provided by Prism as out of the box in the following chapter of the documentation:

I hope you find this useful,

Agustin Adami