试图将IEventAggregator注入Prism Shell中不起作用-想法? [英] Trying to inject IEventAggregator in Prism Shell not working -- ideas?

查看:308
本文介绍了试图将IEventAggregator注入Prism Shell中不起作用-想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让我的引导程序创建了shell的实例:

 受保护的 覆盖 DependencyObject CreateShell()
{
    MainWindow shell =  MainWindow( this  .Container.Resolve< IEventAggregator>());
    返回 shell;
}

受保护的 覆盖  void  InitializeShell()
{
    基本.InitializeShell();

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



而且我的shell正在使用构造函数:

  public  MainWindow(IEventAggregator聚合器)
{
    InitializeComponent();
     .DataContext = ;
     .eventAggregator =聚合器;
    eventAggregator.GetEvent< BusyIndi​​cator>().Subscribe(SetIndicator,ThreadOption.UIThread);
}



但是,我发现了两个问题:框架想要调用空的构造函数,并且在向Shell添加空的构造函数之前一直得到null异常.
然后,如果初始化的IEventAggregator最终为null,则在该逻辑中向Assert添加一个测试.毫不奇怪,它为空.因此,出于某种原因,即使调用了InitializeShell()并设置了窗口,系统也会重新创建它(Prism?).

关于如何将事件聚合器注入我的棱镜应用程序外壳中的任何建议?我不应该调用base.InitializeShell()吗? (尽管在执行BootStrapper.Run命令后对外壳的空构造函数进行了调用)我使用Prism 4.1和Unity 2.0在4.0框架下将其构建为WPF应用程序.解决方案

您极不可能在这里获得此问题的答案.您取决于这里使用Prism徘徊并看到您的问题的极少数人.这可能不会很快发生.

提出问题的一个更好的地方是专门讨论棱镜的论坛,请此处 [ 受保护的 重写 DependencyObject CreateShell() { Shell Shell = Container.Resolve< shell>(); shell.Show(); 返回 shell; } </ shell >



您的shell构造函数应类似于:

 私有 IEventAggregator _eventAggregator;
公共新建(IEventAggregator聚合器)
{
InitializeComponent();

_eventAggregator =聚合器;
} 



这样,aggregator参数将不会为null.

我真的建议您查看Prism下载随附的示例.


I have my bootstrapper creating an instance of the shell:

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:

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.

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[^].


If it helps. You are trying to create the shell in the wrong way. The create shell method should look like:

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



Your shell constructor should be something like:

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.


这篇关于试图将IEventAggregator注入Prism Shell中不起作用-想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆