Requests for comment/Dependency injection/2014

This RFC proposes a lightweight mechanism for dependency injection. An implementation with tests and examples is provided. We could combine a facility like this with improved autoloading, and could add it to core as a first step in an iterative development process. Other options are also discussed.

Problem statement
Dependency injection is a design pattern that can facilitate unit testing, loose coupling and architecture description. Although its usefulness varies from one language to another, it is a well-established pattern, and there is a solid ecosystem of supporting libraries for PHP.

Mediawiki doesn't have dedicated facilities for dependency injection, though it has been discussed, and some code in core does DI by hand. Wikibase does have classes for DI (discussed below).

Adding simple DI facilities to core would be a first step towards supporting this pattern. Since at least a few iterations and use cases will probably be needed to get it right, this first step could be considered a kind of "internal API beta feature".