Topics: Prism v4 - WPF 4
Feb 3, 2011 at 9:48 AM

'ello all

I'm new to Prism so please bear with me :)

I am writing a Prism App base on the Stock Trader Example.

What is the recommended way to get an instance of the CompositionContainer in the Bootstrapper?  I'm creating an object outside of the mef framework that I then need to run through the SatisfyImportsOnce method.



Feb 3, 2011 at 5:49 PM

Hi Hein,

MefBootstrapper implements a protected property Container, which is the default instance of the CompositionContainer object.

You can read more about the Bootstrapper in a Prism application here.

I hope you find this information useful.


Miguel Bronzovic


Feb 4, 2011 at 8:15 AM
Edited Feb 4, 2011 at 8:17 AM

Hi there.  Thanx for the reply.

On reading my question again, I see I was not very clear. 

My problem is this.  I'm loading a treeview, so the imports of the viewModel of the treeview are automatically injected.  Then I dynamically load all the items in the tree & create viewModels for them.  Because I'm creating these viewModels, their imports are not injected.

My solution to this is to export the container in the bootstrapper' ConfigureContainer override

protected override void ConfigureContainer()

            //Export the CompositionContainer so we can import it if neccesary.


Now the Container is available to be imported by my TreeViewModel, so I can pass it as a parameter in the constructors of the individual viewModels of the treeitems.  Each treeItemViewModel can now run SatisfyImportsOnce(this) to inject their dependencies.


Is this the correct way to do this, or is there a better way?




Mar 24, 2011 at 7:07 PM

Did you ever find a better way to achieve this behavior?  I'm having the same issue and wondering if there is a more efficient way to do this?

Mar 28, 2011 at 3:17 PM


In order to achieve this behavior, one possibility would be to use the ServiceLocator to retrieve the instances that you need to use from the MEF container. In order to access the ServiceLocator, you can use the ServiceLocator.Current static property.

I hope you find this helpful.

Guido Leandro Maliandi

Mar 28, 2011 at 6:00 PM

That is exactly what I was after, thanks much!

Jul 3, 2011 at 12:36 PM
Edited Jul 3, 2011 at 12:39 PM

Intellsense indicates ServiceLocator.Current only provides about 6 methods of the form GetInstatnce...  In my particular case I need to call ComposeExportedValue and it looks like you needed SatisfyImportsOnce.  To achieve this goal do we do something like below.  If this is indeed possible does it defeat the purpose of ServiceLocator which hides the particular container.  Why doesn't ServiceLocator provide more features of the underlying container like exporting (Pretty Important)?  Also I don't really understand the difference in my 2 options below as ServiceLocator.Current exists without any import required (However Prism always imports IServiceLocator)).

 IServiceLocator _MyServiceLocator;






Jul 4, 2011 at 9:02 PM


We have provided an answer in the following thread, regarding how to access via Composition Container through ServiceLocation.

On the other hand, regarding your second question there is no significant differences since using the ServiceLocator.Current property or if you choose to inject it in your component as an imported value. For a matter of simplicity we commonly use the first choice.


Miguel Bronzovic