Context
Currently, all services in the EntitySchema extension are instantiated sporadically and on demand in various implementation classes. However, in order to increase testability and decrease coupling between classes in the codebase, it would be advisable to implement a Dependency Injection pattern.
Luckily, MediaWiki offers a way to register services in it's MediaWikiServices container, to allow us to implement dependency injection while still leveraging the registration of handler classes for common integrations, such as Content Handling, Special pages, API Modules and hook registration.
For more information about the MediaWiki service container, see:
- https://doc.wikimedia.org/mediawiki-core/master/php/dependencyinjection.html
- https://www.mediawiki.org/wiki/Dependency_Injection#Service_Wiring
Main Objectives
Similarly to what was done for the WikibaseRepo and WikibaseClient extensions in T268600: Implement services through MediaWikiServices, we would like to register each of the services instantiated in the Entity Schema content handler classes, action classes, hooks and special pages with the MediaWiki service container. This involves:
- Registering each of the service classes as described in: https://www.mediawiki.org/wiki/Dependency_Injection#Service_registration_in_extensions
- Utilize the services key in each of the classes listed in extension.json to leverage registration with the MediaWiki service container for dependency injection (example)
Considerations
While a bulk of this work will most likely be completed with upcoming feature development in EntitySchema, it is pivotal that the migration is complete, in order to ensure consistency in the patterns employed in the codebase and avoid degradation of the codebase's comprehensibility by mixing various code organization ideas.