How to: Populate the Module Catalog from XAML in a WPF application using the Composite Application Guidance for WPF & Silverlight (Prism-v2)

The other day I was trying to create a new WPF Prism application and I wanted to be able to load modules from XAML. To make things simpler I decided to check the documentation, but was not able to find any example on how to get this done, as the sample is for Silverlight applications. After this "revelation" I started my research on how this could be done. The most important question was what to put in the Ref attribute, which is where the module assembly is located.

First, and as it is done in the Silverlight approach, the GetModuleCatalog method of the UnityBootstrapper must be overriden with code similar to this:

protected override IModuleCatalog GetModuleCatalog()
      {
          return
             ModuleCatalog.CreateFromXaml(
                 new Uri("/ProjectName;component/ModulesCatalog.xaml", UriKind.Relative));
      }

It came to my mind that I had once answered a related question in the Prism forums, so I thought that would be a good place to start. As it is explained in the question, the Ref attribute must start "file://", but what else should I add to this attribute?

It turns out the answer is quiet simple (fortunately). You simply have to make sure the module's assembly is copied when built in the same folder as your Shell project is and since one of the module's I wanted to load was called SearchModule, this is the XAML outcome:

<prism:ModuleInfo Ref="file://SearchModule.dll"
            ModuleName="SearchModule"
            ModuleType="SearchModule.ModuleInit, SearchModule, Version=1.0.0.0"
            InitializationMode="WhenAvailable">
</prism:ModuleInfo>

The rest of the attributes remain the same as in the Silverlight approach.

I hope this is useful and saves you some trouble for you if you take this approach to load modules in your Prism WPF application.