News Feed
Sections




News Archive
feed this:

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

Paul Jones:
Quicker, Easier, More Seductive How To Tell A DI Container From A Service Locator
December 17, 2013 @ 13:55:11

Paul Jones has continued his posts about dependency injection containers versus service locators in his site with this new post that hopes to make it easier for you to tell the difference between the two.

It is easy to confuse a Dependency Injection container with a Service Locator. They are very similar to each other. The differences are subtle. Indeed, it's even possible to use a Dependency Injection container as a Service Locator, although I think it's difficult to use a Service Locator as a Dependency Injection container. They are both sub-patterns of a more generic pattern called Inversion of Control, and some people confuse the term Dependency Injection with the more generic term Inversion of Control.

He starts off with a few questions you can ask to see which camp the implementation belongs in, mostly revolving around how the objects are fetched. He includes some code samples to help reinforce the point, showing both a service locator and DIC. He's also done some looking around at some of the major DIC implementations and which of the two he sees them as (with a few notes explaining his thoughts).

0 comments voice your opinion now!
service locator dependency injection compare inversionofcontrol

Link: http://paul-m-jones.com/archives/5843

PHPMaster.com:
Inversion of Control - The Hollywood Principle
December 10, 2012 @ 09:43:50

In this new tutorial on PHPMaster.com, Alejandro Gervasio looks at the Inversion of Control methodology and how it's more than just an abstract reference to dependency injection.

Traditionally, application components have been designed to operate on and control the execution environment, an approach that delivers well to some extent. [...] Instead of making the module completely responsible for logging data to multiple endpoints, we can transfer the responsibility straight to the external environment. [...] Not surprisingly, the process of inverting these responsibilities between components and the environment is formally known as Inversion of Control (or in a more relaxed jargon, The Hollywood Principle), and its implementation can be a real boost when it comes to developing extensible, highly-decoupled program modules.

He uses a set of domain objects (Posts and Comments in a typical blog structure) and the Observer pattern to show how mixed up things might get if the application isn't carefully coded. He takes this and updates it to include a "comment notification service" that implements the SplObserver and is attached to the post to be executed on an event (in this case, the setting of a new comment).

0 comments voice your opinion now!
inversionofcontrol hollywood principle introduction listener observer tutorial


Reese Wilson:
Using the ServiceManager as an Inversion of Control Container (Part 1)
October 01, 2012 @ 08:04:02

The this recent post to his blog Reese Wilson looks at using one of the modules of the Zend Framework v2, the ServiceManager, as an inversion of control container in your app.

In Zend Framework 1, it was difficult to follow best practices when it came to writing testable code. Sure, you could make testable models, but once you need those models in a controller, what do you do? Zend Framework 2 makes it much easier. In this post, I'll cover the basics of injecting a model into a controller. The main goal here is to be able to wire up and configure your application from the highest level possible. Constructor injection + inversion of control makes it easy to determine which classes are dependent on other classes.

He creates a "Building" module and a "BuildingController" inside of it. This controller takes in an instance of a "Building" model as a dependency. He also shows how to define this dependency in the "getControllerConfig" method of your module to make it work automatically. He makes the "Building" model itself with no dependencies and sets it up as an "invokable" in that same "getControllerConfig" method.

0 comments voice your opinion now!
servicemanager zendframework2 inversionofcontrol ioc designpattern


Christopher Bledsoe's Blog:
PHP Dependency Injection (Inversion of Control)
January 10, 2011 @ 09:39:03

On his ClickMagnate site Christopher Bledsoe has an interesting post looking at dependency injection (or, as he calls it "inversion of control") in PHP applications.

.NET and Java have some great IoC (Inversion of Control) containers but PHP hasn't gotten the same kind of dependency love (I know there are a few people who have tried to tackle this problem but I wanted something that worked with Zend Framework - my framework of choice). I also wanted the dependencies to be defined via the application.ini that Zend Framework uses... So, here's my attempt at that.

He includes both the configuration (Zend Framework based) of his dependency injection (DI) class that lists the classes each instance needs to have injected and the code for the actual DI class. The process looks at the configuration file and, if it finds something with the current class name, creates an instance of the class to inject and push it into the controller.

3 comments voice your opinion now!
dependency injection inversionofcontrol zendframework tutorial



Community Events





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


code refactor opinion threedevsandamaybe developer interview podcast framework install configure wordpress language testing unittest community laravel release list series introduction

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