Backend and Infrastructure

Dependency Injection Container

Sprout Video

Our project now has services, an interface, and is fully using dependency injection. Nice work! One of the downsides of DI is that all the complexity of creating and configuring objects is now your job. This isn’t so bad since it all happens in one place and gives you so much control, but it is something we can improve! If you want to make this easier, the tool you need is called a dependency injection container. A lot of DI containers exist in PHP, but we're going to use Composer to grab the simplest one of all, called Pimple. (If you are unfamiliar with Composer, you should watch The Wonderful World of Composer tutorial.)

Additional resources

The Wonderful World of Composer
Composer download
Pimple
To learn how to apply these concepts in Drupal 8 module development, check out the Module Development Essentials series, starting with Understand the Service Container.