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:
(Basic) Configuring the Magento 2 Dependency Injection Container
December 16, 2013 @ 12:03:22

Kevin Schroeder continues his series of posts looking at using Magento 2 and creating customizations of the application. In this latest post he builds on the previous post about dependency injection and shows how to configure Magento's container.

The purpose of that post was to, perhaps, make you less apprehensive about using DI combined with the DIC in Magento 2. However, in this post I want to go a little deeper into the DIC, implemented via the MagentoObjectManagerObjectManager class, and talk about how to configure it. Configuration for the DIC is done in each module's etc/di.xml file or etc//di.xml. Because you can split DIC configuration based on the area this tells you that the /config/ naming stuff is over; which I applaud.

He focuses more specifically on two of the child nodes that can be defined - "type" and "preference" (you can also have "virtualType" as well). First up is "type" and he gives a simple example class in his "HelloWorld" example that just takes in a message and returns it when asked. He shows it in use and how to set up the "di.xml" configuration for the class, defining the "message" parameter in the configuration instead of in the object fetch (like the first example).

0 comments voice your opinion now!
magento2 dependency injection container configuration usage tutorial

Link: http://www.eschrade.com/page/basic-configuring-the-magento-2-dependency-injection-container/

blog comments powered by Disqus

Similar Posts

The Bakery: New Updates - Helpers, Tutorial and Articles

MSBWare.com: Alternating Row Colors

DZone.com: GladiusDB and Firebird: Databases for Your PHP Apps

Ralph Schindler's Blog: Compiling Gearman (or anything) for Zend Server CE on Snow Leopard

Carson McDonald's Blog: Building HipHop PHP for Fedora 12 on 64 bit and 32 bit Systems


Community Events

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


community list podcast example library extension symfony2 voicesoftheelephpant opinion framework api release performance laravel php7 conference series interview version introduction

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