Services and Containers in Drupal 8

This article is part of an archive of articles that were formerly on the web site of Poplar ProductivityWare LLC, Jennifer's freelance software development business (which closed for business in April 2022).
Author: Jennifer Hodgdon
Date Written: 19 October, 2014
Type: Presentation
Subject: Drupal

On October 18, 2014, I gave at talk at the Pacific Northwest Drupal Summit entitled "Services, Dependency Injection, and Containers, oh my!". Description:

Drupal 8 introduces the concepts of Services, Dependency Injection, and the Container to Drupal. They my seem a bit mysterious to programmers who are used to working with Drupal 7 or earlier versions. To help clear up the mysteries, this session will answer these questions:

  • What is a service?
  • What are those $container variables all over the code?
  • What are dependencies, and what is injection?
  • What's the easiest way to interact with services, and ... since you're about to tell me how wrong it is to do it that way, how should I really be doing it in my code?
  • How can I override a service?
  • Why is this all important (why did Drupal adopt this conceptual framework in the first place)?

Slides are attached below.