how to obtain module instance in LoadModuleCompleted

Topics: Prism v4 - Silverlight 4
Mar 4, 2011 at 1:01 AM


I was wondering if anyone knows how to obtain the module instance for which ModuleManager.LoadModuleCompleted fires? In other words, when the ModuleManager.LoadModuleCompleted event fires, it fires for a module. In the event args I have access to the ModuleInfo for which the event fired but I don't have access to the actual IModule instance. This is what I need. It's not clear to me on how to acheive this. The ModuleInfo.ModuleType does not really help me because most of my modules will be of the same type. You see I don't use PRISM exactly how it should be used. Because most of my modules consist of simply an entry level view/viewmodel that gets displayed in a window, I basically have one type that implements IModule and my various modules use this same type. But I nonetheless need to keep track of these instances. For me it would be ideal to somehow obtain the IModule instance from within LoadModuleCompleted. I know I can achive this in other ways, like for example, having my common module type call something within its Initialize method passing itself in, which is what I have done in the past with PRISM, but now I am looking to do this inside LoadModuleCompleted. Anyone know how? I am not a PRISM expect by far so perhaps I am missing something obvious, but I feel there is a disconnect between ModuleInfo and the IModule instance created for it at runtime. Another option that would work well for me is being able to obtain within IModule.Initialize the corresponding ModuleInfo. Anyone have any ideas? Thank you very much

Mar 4, 2011 at 5:12 PM


Take into account that your scenario is not taking advantage of modular application development proposed by Prism. You should separate your functionality into modules in order to make your application architecture flexible and maintainable. Each of these pieces encapsulates specific functionality, and is integrated through clear but loosely coupled communication channels.

On the other hand, as Prism documentation shows “Module instance lifetime is short-lived by default. After the Initialize method is called during the loading process, the reference to the module instance is released. If you do not establish a strong reference chain to the module instance, it will be garbage collected.

This behavior may be problematic to debug if you subscribe to events that hold a weak reference to your module, because your module just "disappears" when the garbage collector runs.

One possible way to fulfill your requirement is to use Event Aggregator mechanism, by publishing an event on in the LoadModuleCompleted handler and subscribing to that event in your module, for example to register something in your container.

You can read about these topics in the following links:

I hope you find this information useful.


Miguel Bronzovic


Mar 4, 2011 at 9:15 PM

Thank you

Indeed you have provided the info I need...