据我了解, IServiceLocator 是一个抽象实际 IoC 容器的接口?我问的是与 Prism 相关的问题,我想在哪里用 Prism 替换 Unity https://stackoverflow.com/questions/2621248/using-prism-with-ninject,我看到 Prism 类依赖于 IServiceLocator。有人可以澄清该接口的作用以及何时使用它吗?
并且;是什么通用服务定位器 http://commonservicelocator.codeplex.com/Wikipage,这在使用 IServiceLocator 时会有帮助吗?
IServiceLocator 是服务定位器的抽象。 IoC 容器是服务定位器的超集,因此它们可以用 IServiceLocator 表示。然而,服务定位器模式比纯依赖注入模式更具侵入性,因此您应该尽可能选择后者。
CommonServiceLocator 提供 IServiceLocator 接口和该接口的抽象实现来定义公共行为并帮助 IoC 容器定义其 IServiceLocator 适配器(每个主要的 IoC 容器都提供这样的适配器)。
也可以看看:
- http://martinfowler.com/articles/injection.html#ServiceLocatorVsDependencyInjection http://martinfowler.com/articles/injection.html#ServiceLocatorVsDependencyInjection
- http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)