Dependency injection in Drupal 8


Since the released of D8 with symphony and contrib module, everyone has been trying to contribute as much and as fast as possible. 
However the thought process has not yet moved to Drupal 8 style of coding (best practices not yet employed). The challenge here is the lack of design patterns in Drupal 7; where all modules designs were different.

For many the questions that pops up are: "What is Services and Dependency Injection? How does it help me?"

The way I see the answer to second question is 

  • It enables us to reuse the functionality and make our services pluggable and replaceable.
  • To undestand and use best practices such as using service container in a decoupled manner.

In Drupal 8 We have many services and Dependency Injection Containers which give super powers to our Drupal 8 modules.
It's paramount that we understand and use them in Drupal 8 module development.

My session will talk about various scenerios and how can we use different services and Dependency Injection in these scenerios.
The session will include demos, examples and code walk throughs.

Here're the objective of the session:

  • Overview of Services and Dependency Injection?
  • Drupal 8 core services and how to use them.
  • How to use Dependency Injection in a Drupal form?
  • How to use Dependency Injection in Contrib modules?

What level of knowledge should attendees have before walking into your session:

This session will be easy to understand for people with intermidiate level knowledge of Drupal. However the session should be open for beginners.

Take Away for attendees:

  • Best practices of building custom and contrib module using services and dependency injection.
  • How to's for business logic of modules?
  • Understanding of using DRY methodology.
  • Keeping module in decoupled manner. 

Session Track


Experience Level


Drupal Version

When & Where

Tuesday, 10 May, 2016 - 13:00 to 14:00
262 [Trellon]