问题描述
我的问题是如何在Xamarin.Forms的iOS项目的类中使用IEventAggregator
来发布消息.
My question is how can I use the IEventAggregator
inside a class in iOS project of Xamarin.Forms to publish a message.
将IEventAggregator
作为构造函数参数传递似乎无效.似乎该依赖关系无法在iOS项目中解决.因此,如何解决iOS项目中IEventAggregator
的依赖关系,以便可以在类中使用它进行发布.
Passing the IEventAggregator
as a constructor parameter doesn’t seems to work. It seems that the dependency cannot be resolved in the iOS project. So how can I resolve the dependency of IEventAggregator
in the iOS project so I can use in a class to publish.
我正在使用Prism 6.3.0
I'm using Prism 6.3.0
推荐答案
PrismApplication的容器是公共属性.因此,您可以访问容器来解决您的依赖性,例如:
PrismApplication's Container is a public property. You can thus access the container to resolve your dependency like:
var ea = ((App)Application.Current).Container.Resolve<IEventAggregator>();
ea.GetEvent<SomeEvent>().Publish(somePayload);
这篇关于Xamarin形成Prism如何在iOS项目中使用IEventAggregator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!