Problem with event LoadModuleCompleted

Topics: Prism v4 - WPF 4
Jan 19, 2011 at 3:32 PM

Hi,

I have a very strange problem, I am trying to use the event LoadModuleCompleted but it won't fire. For reference, I used the StockTrader Reference Implementation for desktop, I have put the folowing code in the Shell.cs :

[Export]

public partial class Shell: Window, IPartImportsSatisfiedNotification

{

   [Import]

   ShellViewModel ViewModel { set { this.DataContext = value;}}

   [Import(AllowRecomposition = false)]

   public IModuleManager ModuleManager;

   public Shell() { InitializeComponent(); }

   public void OnImportsSatisfied() { this.ModuleManager.LoadModuleCompleted += new EventHandler<LoadModuleCompletedEventArgs>(ModuleManager_LoadModuleCompleted); }

   void ModuleManager_LoadModuleCompleted(object sender, LoadModuleCompletedEventArgs e) { Console.WriteLine("Module Loaded"); }

}

The OnImportsSatisfied method is called but it seems that I never enter the ModuleManager_LoadModuleCompleted.

It is very strange because the modules are loaded. Is it a problem with MEF, or am I missing something ?

Jan 20, 2011 at 3:38 PM

Hi,

The issue you're experiencing could be because of a timing issue. That is to say, at the time your modules are loaded, you possibly haven't subscribed to that event, since the modules could have been loaded before OnImportsSatisfied method is called. One possible workaround in case it is a timing issue could be to make your modules load on demand, and call the ModuleManager.LoadModule method to load them in your OnImportsSatisfied method, explicitly after subscribing to the ModuleManager.LoadModuleCompleted event.

I hope you find this information useful.

Thanks,

Miguel Bronzovic
http://blogs.southworks.net/mbronzovic