Dependency Injection sounds like a fancy term for something complicated and advanced. After all, most people didn’t start hearing about this until recently when the PHP world was overtaken by object oriented programming. Dependency Injection sounds intimidating, but it is not. It is simple to understand and once you do, using it in PHP and Drupal is very easy.
In this session, you will learn what Dependency Injection is and how it helps you structure your programs better. You will learn some very basic concepts like constructor injection with analogies and examples and then move on to see how it is done in real life.
Most times, dependency injection is implemented with containers. You will learn how to use some simple dependency injection containers like Pimple in your PHP application. You will also learn how dependency injection is implemented in frameworks like Laravel and Symfony. We will focus on Symfony the most since Drupal uses Symfony’s dependency injection container.
By the end of the session, you will understand:
- What is Dependency Injection and how does it help us
- Constructor and setter injection
- Why do we need Dependency Injection Containers
- How to use Dependency Injection in simple PHP applications and frameworks like Laravel
- How to use Dependency Injection in Symfony and Drupal 8
- How to write YAML files to define services and their dependencies