Date Published: October 13, 2020
The Service Locator Pattern decouples an application from its services.
Pluralsight's Design Patterns Library course has a module on the Service Locator Pattern from John Brown.
Service Locators are often useful in the implementation of logging because it is independent of specific business functions and is used throughout the application, but is often changed based on environmental needs. A Service Locator can be used to abstract the logger from the application, allowing the code to follow the Open/Closed Pattern.
"Abstract the application from the services it uses" - sit between the application and its services to simplify their interactions. In this way, it reminds me a bit of the Repository Pattern.
Some drawbacks to Service Locator: it is global, and a service it refers to may not be loaded.
Thanks for reading! I hope you find this and other articles here at ilyanaDev helpful! Be sure to follow me on Twitter @ilyanaDev.