Accessing Prism's IOC Container from App.xaml

Topics: Prism v1, Prism v2 - WPF 3.5
Dec 18, 2009 at 2:24 AM

I am creating a Prism 2.1 app in which I have implemented logging, using Log4Net in a custom logger derived from ILoggerFacade. Logging works great; I simply resolve ILoggerFacade against the IOC Container, and it returns my logger, to which I send a message in the usual manner.

Here is my problem: I want to log the application exit, and the logical way to do this seems to be to override OnExit() in App.xaml.cs. But I can't figure out how to get a reference to the Container from App.xaml.cs, so that I can resolve my logger.

Can I reference the Prism IOC Container from App.xaml.cs? If so, how? Thanks.

Dec 20, 2009 at 9:16 AM
Edited Dec 20, 2009 at 11:32 AM

Your bootstrapper has access to the Container.  You could create a method on the bootstrapper, like LogMessage(string message).

We do a similar thing in the bootstrapper with the AppDomain.CurrentDomain.UnhandledException event to log any exceptions.