【问题标题】:Prism.Unity.Wpf problem: UnityServiceLocatorAdapter is missing after update [closed]Prism.Unity.Wpf 问题:更新后缺少 UnityServiceLocatorAdapter [关闭]
【发布时间】:2021-03-01 06:30:44
【问题描述】:

将 WPF 应用程序中的 Prism 从版本 7.2.0.1422 更新到版本 8.0.0.1909 后,GetInstance 方法不再起作用: CommonServiceLocator.ServiceLocator.Current.GetInstance 发出消息:“必须设置 ServiceLocationProvider” 我发现版本 8 缺少版本 7 中存在的 Prism.Unity.Wpf.UnityServiceLocatorAdapter 类,它提供了 ServiceLocator 工作。 问:我现在如何利用 CommonServiceLocator.ServiceLocator.Current.GetInstance?

【问题讨论】:

  • 我不明白你的问题。从根本上说,您和 Prism 不需要知道任何关于 CommonServiceLocator.ServiceLocator.Current.GetInstance 的信息。

标签: c# wpf prism


【解决方案1】:

Prism 8.0 的release notes 声明一个重大变化:

添加了 ContainerLocator(注意:这取代了 Prism.Wpf 中的 Common Service Locator)

因此,使用 Prism 8,您可以编写

Prism.Ioc.ContainerLocator.Container

如果您绝对必须访问容器...

【讨论】:

  • 谢谢。你的建议确实帮助了我。现在,我打电话给_eventAggregator = (IEventAggregator) Prism.Ioc.ContainerLocator.Container.Resolve (typeof (IEventAggregator));,而不是_eventAggregator = CommonServiceLocator.ServiceLocator.Current.GetInstance <IEventAggregator> ();,它可以工作了!很遗憾,旧选项已被删除。它更加简洁和通用。
  • 无论如何应该Resolve的通用变体,也许你错过了扩展方法?
  • 使用 Prism.Ioc 添加;应该能解决问题
猜你喜欢
  • 1970-01-01
  • 2015-06-18
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
相关资源
最近更新 更多