Composite event inside custom ILoggerFacade

Topics: Prism v2 - WPF 3.5
Mar 11, 2010 at 2:10 PM

Hi there,

Is it possible to publish a CompositePresentationEvent inside ILoggerFacade.Log() ?

For example, I've created an event called MessageLoggedEvent and I want to raise it inside Log() so that another module can respond to it and display the collected messages in a window.

I've tried overriding UnityBootstrapper.LoggerFacade { get; } property but it seems the Container is created after the getter is called inside UnityBootstrapper.Run(). Therefore I'm not able to get a reference to IEventAggregator.

Is there a solution?



Mar 18, 2010 at 12:33 PM


I’ve come to the following workaround for your situation.

  1. You could use Property Injection to add the EventAggregator as a dependency to the logger you are using:
    public IEventAggregator EventAgg {get; set;} 
  2. Update the Bootstrapper to have the container call the BuildUp method on the logger you are using, so that the dependencies (in this case, the EventAggregator) are injected into it. This must be done after all services are created, for example after the ConfigureContainer method is called:
  3. You can use a conditional like this inside the Log method of your logger to check whether the EventAggregator instance has already been added, and publish the desired event:
    if (EventAgg != null)


Another approach for resolving the EventAggregator inside the logger would be to use the ServiceLocator, but you must take into account that the EventAggregator must be already registered in the container at the time the ServiceLocator is used to resolve it. You can find more information about how to use the ServiceLocator in this thread.

I hope you find this helpful.

Guido Leandro Maliandi