Last post Oct 21, 2016 08:13 AM by Cathy Zou
Oct 20, 2016 01:13 PM|sudip_inn|LINK
please discuss with example what is service locator and how it is different from DI.
Oct 20, 2016 01:28 PM|senthilwaits|LINK
As per Martin Fowler
With service locator the application class asks for it explicitly by a message to the locator. With injection there is no explicit request, the service appears in the application class – hence the inversion of control.
With Dependency Injection, the service injects the dependencies from outside into a class during bootstrapping. It creates the controller class and injects its dependencies from outside, without being used in the controller
In Service locator the dependencies of a class are being pulled from inside that class.
For more details, refer
Oct 21, 2016 08:13 AM|Cathy Zou|LINK
Service Locator :The Service Locator pattern does not describe how to instantiate the services. It describes a way to register services and locate them. Typically, the Service Locator pattern is combined with the Factory pattern and/or the Dependency Injection
pattern. This combination allows a service locator to create instances of services.
The following is good article about what is Service Locator:
Dependency Injection: "Dependency injection is a software design pattern in which one or more dependencies (or services) are injected, or passed by reference, into a dependent object (or client) and are made part of the client's state. The pattern separates
the creation of a client's dependencies from its own behavior, which allows program designs to be loosely coupled and to follow the dependency inversion and single responsibility principles. It directly contrasts the service locator pattern, which allows clients
to know about the system they use to find dependencies
Difference between service locator and dependency injection: