IEventAggregator in View

Topics: Bootstrappers & IoC
Jan 2, 2012 at 12:56 PM


I am using Coding4fun progressoverlay control in my Windows Phone 7 app. This control has Hide and Show methods for displaying the progress bar.

So in order to show and hide the progress bar I need to write the code in the code behind , (I would be intrested if this can be done in ViewModel).

So I have subscribe to events in the view. My viewmodel publishes this event

But when I use IEventAggregator in the constructor of view , my app doesn't get loaded. I assume the dependency injection is failing.


Below is the code of constructor on MainPage (view

public MainPage(IEventAggregator events)
   = events;

Can anyone help me to achieve this.



Jan 2, 2012 at 2:20 PM

DI doesn't work on views out of the box. I'm sure that someone here has come up with a nice solution for the progress indicator though. 

Dec 18, 2013 at 12:31 PM
Same problem...
Maybe just pump resolved view instance through IoC.BuildUp (after InitializeComponents()) ?
At least it helps implement property injection and dispense with service locator.
Dec 18, 2013 at 11:27 PM
in the Constructor of your view
public class SomeView(){
  IEventAggregator _events;
  public SomeViewConstructor(){

   Bootstrapper bootstrapper = Application.Current.Resources["Bootstrapper"] as Bootstrapper;

   _events = bootstrapper._container.GetInstance<IEventAggregator>();

Dec 19, 2013 at 3:52 AM
2 mvermef:
For service locator approach i'm better will do so: IoC.Get<IEventAggregator>(null).
But my desire is do without it.
Dec 19, 2013 at 6:00 AM
Edited Dec 19, 2013 at 6:02 AM
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue<IEventAggregator>("Test", new EventAggregator());


how to Destroy or release these batch and IEventAggregator ,in Dispose()?