【发布时间】:2017-10-14 02:03:21
【问题描述】:
我的问题是如何在 Xamarin.Forms 的 iOS 项目的类中使用 IEventAggregator 来发布消息。
将IEventAggregator 作为构造函数参数传递似乎不起作用。似乎无法在iOS项目中解决依赖关系。那么如何解决iOS项目中IEventAggregator的依赖关系,以便在类中使用发布。
我正在使用 Prism 6.3.0
【问题讨论】:
标签: xamarin.forms prism
我的问题是如何在 Xamarin.Forms 的 iOS 项目的类中使用 IEventAggregator 来发布消息。
将IEventAggregator 作为构造函数参数传递似乎不起作用。似乎无法在iOS项目中解决依赖关系。那么如何解决iOS项目中IEventAggregator的依赖关系,以便在类中使用发布。
我正在使用 Prism 6.3.0
【问题讨论】:
标签: xamarin.forms prism
PrismApplication 的 Container 是一个公共属性。因此,您可以访问容器来解决您的依赖关系,例如:
var ea = ((App)Application.Current).Container.Resolve<IEventAggregator>();
ea.GetEvent<SomeEvent>().Publish(somePayload);
【讨论】:
Application 的类型为App5.iOS.Application,App 的类型为App5.App
Xamarin.Forms.Application
using Application = Xamarin.Forms.Application;
var ea = ((App)Xamarin.Forms.Application.Current).Container.Resolve<IEventAggregator>();。非常感谢。