News Feed
Sections




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

Matt Frost:
Dependency Injection Container Question
February 18, 2013 @ 09:26:17

In his latest post Matt Frost takes a look at dependency injection. He thinks out loud about some of the common uses for it but wonders if there's a middle ground for using a DIC and injecting manual dependencies.

The question I have is what if a dependency in one class also has a dependency? To illustrate what I mean, here's an example with some code to follow. [...] I'm not really concerned about the code here as much as I am about the concept that I'm trying to illustrate, in order to use a dependency injection container for this scenario.

In his example code, he shows a "DBAuthMethod" class that extends the "AuthMethod" interface and an "Auth" class that requires an instance of "AuthMethod" as a constructor parameter. He wonders about constructor versus setter injection and thinks that a mix of the two may not be the best structure for the code.

I just can wrap my mind around a scenario where you could ONLY use a DIC, and if you can't use the concept exclusively what benefit is there to using it?

Have any suggestions to share? Let him know - this is a problem more and more developers run into as DIC becomes more widely used.

0 comments voice your opinion now!
dependency injection container manual constructor setter


blog comments powered by Disqus

Similar Posts

SitePoint PHP Blog: Introducing Bucket: A Minimal Dependency Injection Container for PHP

Jeune Asuncion: ZF1.11 + Doctrine 2 + Symfony DI Integration

MaltBlue.com: Zend Framework 2 Core Concepts - Dependency Injection

PHPMaster.com: An Introduction to Dependency Injection, Service Locators & Factories (Part 1)

SitePoint PHP Blog: Dependency Injection with Laravelís IoC


Community Events





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


language tool security voicesoftheelephpant artisanfiles series introduction opinion composer community laravel framework library list symfony podcast version conference interview release

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