Dependency Injection

If you never heard about dependency injection in Magento 2 you should first take a look at the Magento 2 documentation about dependency injection. If you checked out the the documentation or already are familiar with dependency injection in Magento 2, you will know that there are two ways to inject objects to your constructors. Take the following code as example:

// Vendor\Namespace\Model\SomeClass
// ...
public function __construct(ExampleClass $object) {
    $this->object = $object;
// ...

If you want to inject “$object”, one approach is to use argument replacement, another one is to use class preference. I will shortly describe these two methods and than point out the big difference between them.

Continue reading