• Home
  • Contact
tc-drupal.jpg

Dependency Injection 101

Jesus Manuel Olivas
August 12, 2014

I did have a chance to speak at Twin Cities Drupal Camp last week, the session name was "The Symfony Way".

This session was a walk through at some concepts and components behind Symfony 2, but also, I explained (at least I tried to) how to using them while working with Symfony, Silex & Drupal 8.

One of the mentioned topics was 'Dependency Injection' not sure why but seems for some reason as one of these concepts developers not related to OO are most scared of.

In order to explain this software design pattern I did using the following image:

And this example code to describe it

$redRanger = new PowerRangers\MightyMorphin\Ranger(); $redranger->setName('Jason Lee Scott'); $yellowRanger = new PowerRangers\MightyMorphin\Ranger(); $yellowRanger->setName('Trini Kwan'); $mastodonDinozord = new PowerRangers\MightyMorphin\MastodonDinozord($redRanger); $tigerDinozord = new PowerRangers\MightyMorphin\TigerDinozord($yellowRanger); // Initiate Megazord sequence! $megaZord = new PowerRangers\MightyMorphin\MegaZord(); $megaZord->setMastodonDinozord($mastodonDinozord); $megaZord->setTigerDinozord($tigerDinozord); $megaZord->setMode($megaZord::MODE_BATTLE);

The main goal of this talk was to show using code examples in Symfony, Silex & Drupal 8 and how the three of them are so alike because they share the same foundation libraries and then take advantage of the paradigm "Learn once, use anywhere" but what does this mean?. It means the knowledge you acquire learning this new concepts will be easy to transport and apply on other frameworks.

You can find the slides at this http://2014.tcdrupal.org/session/symfony-way

Ready to embrace the JAMstack revolution?

Build fast and secure sites and apps delivered by pre-rendering files and serving them directly from a CDN, removing the requirement to manage or run web servers, databases and worry about traffic spikes.
Work with us!