Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
Drupal 8: Properly Injecting Dependencies Using DI
May 20, 2016 @ 14:23:41

On the TutsPlus.com site today there's a new tutorial posted for the Drupal-ers out there showing you the right way to inject dependencies in a Drupal 8 application.

As I am sure you know by now, dependency injection (DI) and the Symfony service container are important new development features of Drupal 8. However, even though they are starting to be better understood in the Drupal development community, there is still some lack of clarity about how exactly to inject services into Drupal 8 classes.

They start by talking about how most of the current examples just show the static injection of dependencies but that that's not the only way. The article shows how to inject other services into existing services via a simple change to the service definitions. They also talk about "non-service classes" and injecting values there as well (including controllers, forms and plugins).

tagged: drupal8 inject dependency container dynamic static tutorial

Link: http://code.tutsplus.com/tutorials/drupal-8-properly-injecting-dependencies-using-di--cms-26314


Trending Topics: