The service locator pattern entails removing dependencies from the client object by introducing a mediator. The client object will talk to the mediator to get a desired dependency. We will call this mediator the service locator, or just the locator.
The service locator involves the process of obtaining services with the abstract layer. Ideally, the locator should hold all the services (dependencies) and provide them with a single interface. It is a kind of central repository to find a service, usually by a string or interface type.
The service locator describes how to register and locate the service rather than telling us how to instantiate it. It lets the application register the concrete implementation for the ...