Skip to content

The Service Locator Pattern

software development, coding, pluralsight, design patterns1 min read

service locator pattern

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.

This pattern can benefit from the Observer, Proxy, and Adapter Design Patterns being used alongside it.

Thanks for reading! I hope you find this and other articles here at ilyanaDev helpful! Be sure to follow me on Twitter @ilyanaDev.