I'm currently refactoring my Zend Framework based PHP library from using a service locator to (constructor) dependency injection (DI). I feel that it improves my code a lot, but I'm not sure if I should inject all dependencies. A service locator seems easier for dependencies which are used a lot and are unspecific. I have the following dependencies which I still access using a service locator:
- A Zend_Translate object (I need to translate messages everywhere).
- A Zend_Locale object (stores the current language)
- A Zend_Config object (a lot of things are configurable by ini-file)
- Instances of utility classes (for array and string manipulation)
If I injected these dependencies, they'd clutter my constructors and distract from the specific dependencies. For testing, I can just set up these dependencies in my service locator before running the tests. The pragmatist in me says I'm doing just fine, but the purist says I should go all the way with DI.
Would you recommend DI for these types of objects or not?