Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mastering Dependency Injection in D8

Nicolas Grekas
September 26, 2016

Mastering Dependency Injection in D8

The Symfony Dependency Injection component is a centerpiece of D8 core. But did you know you could use it in your own modules? This talk will teach you about dependency injection as a design pattern. It will tell you how it is used in D8, and how you can leverage it for your own needs for coding custom pages/features. We will talk about the container, all kind of service configurations you can do, factories, decorators, configurators, etc. The promise? Decoupling your code to make it maintainable and testable over time. Let's see how a good component and a few best practices make it happen.

Nicolas Grekas

September 26, 2016
Tweet

More Decks by Nicolas Grekas

Other Decks in Technology

Transcript

  1. #DrupalCon @nicolasgrekas Constructor injection > Setter injection* >> Property injection**

    *~ok with circular dependencies, which should be avoided anyway **bad practice really
  2. #DrupalCon @nicolasgrekas Dependency Injection... is like never writting “new” in

    your code* *except for data objects, e.g. new \DateTime();
  3. #DrupalCon @nicolasgrekas The DIC is an object that has all

    the recipes to instantiate “The” objects of your app, recursively
  4. #DrupalCon @nicolasgrekas The DIC is an object that has all

    the recipes to instantiate the services of your app, recursively
  5. #DrupalCon @nicolasgrekas The DIC is verified, built compiled, optimized, dumped,

    cached* *Tags, circular references, aliases, private inlined/removed, abstract removed, parameters resolved, etc.