IModule.Initialized not getting called.

Hi, I am exploring modules using MEF. I have a CustomerModule exported using [ModuleExport], but this module's Initialize() and constructor never gets called. Certainly, it seems I am missing some wire-up code. Here are the relevant parts of code.

Based on the description of your scenario, there doesn’t seem to be any problem with the code you’ve shown here. However you could try re check the
Run’s sequence in your Boostrapper in order to verify everything is running correctly. Remember also to check your
App.xaml.cs code behind and check the OnStartUp method to verify how you are instantiating and calling the
Bootstrapper’s Run method.

You could use WPF using MEF QuickStarts provided with Prism to help you compare the code.

In case you continue experiencing this behavior, it could be helpful if you could provide us with a repro sample (for example, uploading to
SkyDrive) of your solution, so that we can help you find out the cause.

I checked the Bootstrapper Run sequence and it seems to be normal. Here is the sequence of invocation.

protected override IModuleCatalog CreateModuleCatalog()

protected override void ConfigureAggregateCatalog()

protected override void ConfigureContainer()

protected override DependencyObject CreateShell()

protected override void InitializeShell()

I debugged and saw that the AggregateCatalog has all the entries for my modules(Views and ViewModels). So AggregateCatalog is properly populated. But the ModuleCatalog's Modules is Empty Collection. How is that the ModuleCatalog and AggregateCatalog is out
of sync. The Application runs alright (except for region discovery, for which I will probably start a new discussion) , but I don't get a chance to Initialize CustomerModule.cs as it is never called. So in short all parts get exported, except the actual CustomerModule.cs
(which implements IModule).

regards,
Nirvan.

Note: I don't have account with sky drive or any service, so I cannot post the repro. Will open one shortly.

I have my skydrive account active now. What do you want me to upload on skydrive ? I mean, does repro mean the whole solution ? In that case you can find the same
here. After the Shell loads the MainRegoin, click on Customer Button in the toolbar. The CustomerModule Constructor is not invoked at any point.

A repro sample usually means a sample application that is intended to reproduce a specific behavior that you're experiencing. In some cases, a repro sample might be the whole solution, although showing a scenario scoped only to the exact problem that you
want to point out might depict your point in a clearer way.

As for the problems you're experiencing, the problem is caused by the fact that you are experiencing some
CompositionExceptions, due to the fact that you're trying to get imports in an incorrect way. When registering services, it's a common good practice to export types using the interface as the contract; that is to say, if you have (for example)
the EventAggregator class, you should export it with the
IEventAggregator interface as the contract type. Therefore, other components can "know" of the interface, but not of the exact implementation of that interface. Prism follows that approach, and therefore, exports for services use the interface as the
contract type. Therefore, when importing Prism's services, such as the region view registry, you should indicate that your import is of type
IRegionViewRegistry, not RegionViewRegistry. In your sample application, we've replaced all the imports for Prism services with the corresponding interface, and after that, your module was initialized correctly.

Additionally, we've examined your sample and found that you're importing your module's exports (such as the view models for your views) directly in your shell view model (for example, in the
LoadCustomerModule method inside the ShellViewModel class). That might not be a good practice, as you are coupling your shell to your customer module. The approach recommended by prism is to make modules responsible for
adding their views to regions defined in the shell. One possibility to cover that scenario would be to use
Navigation to indicate that you should navigate to your
CustomerMainViewModel in the LoadCustomerModule
method.

Thanks for helping me out resolve the Module Initialization issue and guiding me about the ideal practices. I will surely have a look on Navigation part of Prism Developers guide so that decouple the Modules as much as possible. The issue in this discussion
is resolved.