Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the IServiceLocator interface?

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?

like image 1000
stiank81 Avatar asked Apr 12 '10 10:04

stiank81


1 Answers

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:

  • http://martinfowler.com/articles/injection.html#ServiceLocatorVsDependencyInjection
  • http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html
like image 127
Mauricio Scheffer Avatar answered Oct 06 '22 17:10

Mauricio Scheffer