Backend and Infrastructure

Services and Dependency Injection

Sprout Video

Our app is small now, but as it grows, the app.php file will get harder and harder to read. The best way to fix this is to separate each different chunk of functionality into different PHP classes and methods. Each of these classes is called a “service” and the whole idea is sometimes called Service-Oriented Architecture. In this tutorial you're going to create a new service, and learn about different ways to access external objects from a service. Then, we'll set up our app to use dependency injection to get the job done right.

Additional resources

Service-Oriented Architecture
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.