Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have my bootstrapper creating an instance of the shell:
C#
protected override DependencyObject CreateShell ( )
{
    MainWindow shell = new MainWindow( this.Container.Resolve<IEventAggregator>( ) );
    return shell;
}

protected override void InitializeShell ( )
{
    base.InitializeShell( );

    App.Current.MainWindow = (Window)this.Shell;
}


and I have my shell consuming the constructor:
C#
public MainWindow(IEventAggregator aggregator)
{
    InitializeComponent( );
    this.DataContext = this;
    this.eventAggregator = aggregator;
    eventAggregator.GetEvent<BusyIndicator>( ).Subscribe( SetIndicator, ThreadOption.UIThread );
}


However I found two issues: the framework wanted to call the empty constructor and I kept getting a null exception until I added an empty constructor to the Shell.
Then I added a test in that logic to Assert if the initialized IEventAggregator ended up to be null. No surprise here it was null. So for some reason even though InitializeShell() was called and the window was set, it was recreated by the system (Prism?).

Any suggestions on how to inject the event aggregator into the shell of my prism application? Should I not call base.InitializeShell() ??? (though the call to the empty constructor of the shell occurs after the BootStrapper.Run command was executed) I'm building it as a WPF application under the 4.0 framework using Prism 4.1 and Unity 2.0.
Posted

It's extremely unlikely you're going to get an answer to this question here. You're depending on the very few people here who have used Prism to wandering by and see your question. That's probably not going to happen any time soon.

A better place to asak your question is a forum dedicated to Prism, here[^].
 
Share this answer
 
Comments
SASS_Shooter 30-May-12 11:12am    
Thanks. I'll post the question there.
If it helps. You are trying to create the shell in the wrong way. The create shell method should look like:

C#
protected override DependencyObject CreateShell()
{
	Shell shell = Container.Resolve<shell>();
	shell.Show();
	
	return shell;
}</shell>


Your shell constructor should be something like:
C#
private IEventAggregator _eventAggregator;
public New(IEventAggregator aggregator)
{
	InitializeComponent();

	_eventAggregator = aggregator;
}


Doing it this way the aggregator argument will not be null.

I would really recommend looking at the samples provided with the Prism download.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900