News Feed
Sections




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

Chris Hartjes' Blog:
DIC vs. Service Locator
June 07, 2012 @ 10:09:36

In a new post to his blog, Chris Hartjes shares one thing that you can use to make your code easier to test - using a dependency injection container and how it compares to a service locator.

People often ask me what's the one thing they could do for their code base RIGHT NOW that will make it easier to test. To me, the answer is simple: make sure you are using Dependency Injection (yes the link is long and has code samples in Java, but whatever). Without the ability to "inject" your dependencies into your code (whether it is class methods or functions) you will have problems testing modules of code in isolation from each other.

He shows the possible uses of DICs, including code samples, and talks the differences between the two. He explains that the real difference in them is how its being used. When it's used to add and remove instances, it's a container. When its actually put to use and passed into a class, it morphs into a service locator.

0 comments voice your opinion now!
dependencyinjection servicelocator testing difference


blog comments powered by Disqus

Similar Posts

Gonzalo Ayuso: Dependency Injection Containers with PHP. When Pimple is not enough.

Nola\'s Blog: Test Freak!

PHP.net: PHP 5.5.0 Alpha3 released

Builder.com.au: Get the correct time by converting between time zones with PHP and PEAR

Sebastian Bergmann's Blog: PHPUnit 3.0 Beta 3


Community Events





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


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

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