Prism-WPF equivalent to Silverlight's: CompositionInitializer class and SatisfyImports()

Topics: Prism v4 - WPF 4
Jan 27, 2013 at 8:30 AM

i'm using Prism-MEF-WPF and Sometimes i need view model gets constructed from the XAML
of the view, so the container is not involved and can’t do the dependency injection
automatically (as there is no Export attribute used with VM).So there should be some
class in Prism-WPF like CompositionInitializer   to enable me to ask the container to
do the injection.In case there is equivalent  class how to use it, and in case there is
no equivalent how to construct view model from xaml of the view.

Jan 28, 2013 at 2:33 PM


Based on my understanding the view model can be instantiated in XAML as the view’s DataContext only if a view model does not have any constructor arguments. And as far as I know creating objects defined in XAML by partnering with an Inverse of Control Container is currently not supported.

Regarding the CompositionInitializer class, as far as I know there is no equivalent class for WPF, on the other hand regarding this topic, I believe you could find the following blog post interesting:

Also, I believe an alternative for this could be registering the CompositionContainer class like mentioned in this thread:

As this could let you retrieve this class for example in your view model's constructor, in order to call the SatisfyImportsOnce method to satisfy the Imports defined in the passed class:

this.compositionContainer =ServiceLocator.Current.GetInstance<CompositionContainer>();
I hope you find this handy,

Agustin Adami

Jan 28, 2013 at 5:59 PM


That was very handy, i tested it and it worked. As i know about you your shot always in the goal.