News Feed
Sections




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

Kevin Schroeder:
(Starting) Using Dependency Injection in Magento 2
December 13, 2013 @ 11:50:45

Kevin Schroeder is continuing his current trend of posts with another new one about Magento 2 and using deendency injection and how to use it inside your Magento extension code.

I wrote an introduction to Dependency Injection for Zend Framework a while back and was able to work out some of the kinks in my understanding of how a DI container worked with 4 blog posts. It took a while for me to get it but much of what I learned for Zend Framework does directly apply for Magento 2. Dependency Injection is handled in Magento 2 via the class MagentoAppObjectManager. And if you look at that from within the context of Magento 2 you are probably pooping your pants. 200+ class instances, configuration options, dogs and cats living together.

He starts with a simple script that calls the DI container to get an instance of a "Test" class. He talks about the difference between this and calling "new" and gives a bit more complex example with a custom "Test2" class. It's only slightly more complex as he shows how an instance of "Test2" with a property of a "Test" instance gets created and built out and injected into the "Test2" class on initialization.

0 comments voice your opinion now!
dependency injection magento2 tutorial introduction

Link: http://www.eschrade.com/page/using-dependency-injection-in-magento-2/

blog comments powered by Disqus

Similar Posts

PHPMaster.com: Continuous Integration (with Jenkins), Part 1

KillerPHP.com: Two New Video Tutorials Posted

Cormac's Blog: Fast server-side rejection of large image uploads using $_FILES

PHP-Security.net: Suhosin 0.9.34-DEV Installation HowTo

PHPit.net: An Introduction to the Winbinder Library (Part 1)


Community Events





Don't see your event here?
Let us know!


composer library tool series symfony opinion community update introduction interview podcast security package voicesoftheelephpant framework version mvc laravel language release

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework