Register module from "Executable" instead of Library

Topics: Prism v4 - WPF 4
May 15, 2013 at 8:23 AM
Hello,

I have a project with 2 module libraries ModuleALibrary and ModuleBLibrary using a IUnityContainer to register types.

My Main project uses a Bootstrapper to initialize my UnityContainer.
namespace MainProject
{
 public class MyBootstrapper : UnityBootstrapper
 {
        protected override IModuleCatalog CreateModuleCatalog()
        {
            ModuleCatalog catalog = new ConfigurationModuleCatalog();
            catalog.AddModule(typeof (MainModule), InitializationMode.WhenAvailable,
                              "ModuleB");
            return catalog;
    }
}
}
As you can see my Main project contains a class/module (MainModule) that I need my container to reference. MainModule is dependent upon ModuleB.

As my Main project generates a .exe and not a .dll how can I add my MainModule class to my configuration file and remove the coding line catalog.AddModule().

I know that a Module should not be in a .exe project but I have this requirement for my specific case.

Below my configuration file where I need to add a <module> with an "exe" assemblyFile (yes this sound strange ;):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="modules" type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
  </configSections>

  <modules>
    <module 
      assemblyFile="ModuleALibrary.dll" 
      moduleType="ModuleALibrary.ModuleA, ModuleALibrary" 
      moduleName="ModuleA"/>

    <!-- Main module depends upon the modules above -->
    <module assemblyFile="ModuleBLibrary.dll" 
            moduleType="ModuleBLibrary.ModuleB, ModuleBLibrary" 
            moduleName="ModuleB">
      <dependencies>
        <dependency moduleName="ModuleA"/>
      </dependencies>
    </module>
   
  </modules>
</configuration>
I know that this is possible in Silverlight as we can add a XAP file but how can we do with a WPF application?

Thank you for your help.

Sincerely,
Linvi
May 15, 2013 at 6:37 PM
Hi,

Based on my understanding, adding an .exe assembly file to the configuration file is the same as with other modules you added, but instead of ".dll" extension, you will use ".exe" extension in the assemblyFile field, which refers to the ".exe" file of your MainProject. Therefore, your configuration file should look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="modules" type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
  </configSections>

  <modules>
    <module 
      assemblyFile="ModuleALibrary.dll" 
      moduleType="ModuleALibrary.ModuleA, ModuleALibrary" 
      moduleName="ModuleA"/>

    <!-- Main module depends upon the modules above -->
    <module assemblyFile="ModuleBLibrary.dll" 
            moduleType="ModuleBLibrary.ModuleB, ModuleBLibrary" 
            moduleName="ModuleB">
      <dependencies>
        <dependency moduleName="ModuleA"/>
      </dependencies>
    </module>

    <!-- Main module configuration -->
    <module assemblyFile="MainProject.exe" 
            moduleType="MainProject.MainModule, MainProject" 
            moduleName="MainModule">
      <dependencies>
        <dependency moduleName="ModuleB"/>
      </dependencies>
    </module>
   
  </modules>
</configuration>
Take into account that assemblyFile and moduleType could differ slightly depending on your MainProject assembly name and default namespace properties.

Regards,

Federico Martinez
http://blogs.southworks.net/fmartinez
May 31, 2013 at 12:27 PM
Thank you for your help.

I was trying to do that before but I had an issue with my moduleType parameter and I thought the error was coming from the assemblyFile.

Sincerely,
Linvi