IServiceLocator 接口是什么?

发布于 2024-08-28 08:17:16 字数 365 浏览 5 评论 0原文

据我了解, IServiceLocator 是一个抽象实际 IoC 容器的接口?我问的是与 Prism 相关的问题,我试图用 Prism 替换 Unity,并且我看到 Prism 类依赖于 IServiceLocator。有人可以澄清一下该接口的作用以及何时使用它吗?

还有;什么是通用服务定位器,这在使用 IServiceLocator 时会有帮助吗?

From what I understand IServiceLocator is an interface to abstract the actual IoC container away? I'm asking with relation to Prism where I'm trying to replace Unity with Prism, and I see Prism-classes relying on IServiceLocator. Could someone please clarify the role of the interface and when it is used?

And also; what is the Common Service Locator, and will this be helpful when working with IServiceLocator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美羊羊 2024-09-04 08:17:16

IServiceLocator 是服务定位器的抽象。 IoC 容器是服务定位器的超集,因此它们可以用 IServiceLocator 表示。然而,服务定位器模式比纯依赖注入模式更具侵入性,因此您应该尽可能选择后者。

CommonServiceLocator 提供 IServiceLocator 接口和该接口的抽象实现来定义公共行为并帮助 IoC 容器定义其 IServiceLocator 适配器(每个主要的 IoC 容器都提供这样的适配器)。

另请参阅:

IServiceLocator is an abstraction of a service locator. IoC containers are kind of supersets of service locators so they can be represented by IServiceLocator. However, the service locator pattern is more intrusive than the pure dependency injection pattern, therefore you should try to favor the latter whenever possible.

The CommonServiceLocator provides the IServiceLocator interface and an abstract implementation of this interface to define common behavior and help IoC containers define their IServiceLocator adapter (every major IoC container provides such an adapter).

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文