问题描述
据我了解IServiceLocator是一个接口抽象实际的IoC容器走?我问有关于棱镜的地方我想与棱镜取代团结,我看到依靠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?
和也;什么是公共服务定位,并将与IServiceLocator工作时,这是有益的?
And also; what is the Common Service Locator, and will this be helpful when working with IServiceLocator?
推荐答案
IServiceLocator是一个服务定位器的抽象。 IoC容器中,是一种服务定位器的超集,使他们可以通过IServiceLocator psented再$ P $。然而,服务定位器模式比单纯的依赖注入模式的侵扰,因此,你应该尽量偏向后者只要有可能。
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.
该CommonServiceLocator提供IServiceLocator接口和抽象实现这个接口来定义常见的行为,并帮助IoC容器中,明确自己的IServiceLocator适配器(每一个主要的IoC容器提供了这样的适配器)。
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).
另请参阅:
- http://martinfowler.com/articles/injection.html#ServiceLocatorVsDependencyInjection
- http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html
- http://martinfowler.com/articles/injection.html#ServiceLocatorVsDependencyInjection
- http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html
这篇关于什么是IServiceLocator界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!