 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Happy Accidents: Orno Skinny Series Part 1 Building a RESTful API
by Chris Cornutt March 19, 2013 @ 11:36:54
On the Happy Accidents site there's a new post talking about building a RESTful API (part one of the series) using the Orno dependency injection and MVC components.
have recently been writing a collection of PHP components exploring different design patterns for building applications. With the MVC layer close to completion I decided to write a couple of guides on how these components could be wired together to achieve several different application formats. First in this series will highlight the power of OrnoDi when used to resolve your objects, to do this we will be building a simple RESTful api with the minimal amount of configuration and bootstrap code.
He includes instructions to install the components (via Composer) and configure the DI container with the needed settings. He shows examples of the autoloading setup, how to handle the routing and how to create the sample model and controller to respond to the sample REST requests.
voice your opinion now!
rest api orno component mvc dependencyinjection tutorial
Ralph Schindler: DI, DiC, & Service Locator Redux
by Chris Cornutt October 11, 2012 @ 10:43:38
In his latest post Ralph Schindler takes another look at the usefulness of Dependency Injection Containers and whether or not they're the right thing to use for your situation.
To DiC, or not to DiC: that has seemed to be the question in PHP for the last few years. Most people generally agree that injecting dependencies is the right thing to do. For those writing a framework, or any shared codebase where extensibility or the ability to grow the codebase is a core philosophical tenet, not injecting dependencies is doing a disservice to the project in the long run. So, as I've stated before, the question becomes how do we manage the added complexity that comes with practicing dependency injection?
He briefly covers two topics that are often confused - the concepts of a service locator and a true dependency injection container. He then talks about the more correct situations to use each of them, mentioning a few questions you can ask about your app to determine the best fit. To illustrate, he includes a simple example where he mixed the two - DIC for models and service location for the controllers.
voice your opinion now!
dependencyinjection container servicelocator example dic
Gonzalo Ayuso: Dependency Injection Containers with PHP. When Pimple is not enough.
by Chris Cornutt September 03, 2012 @ 09:51:40
Gonzalo Ayuso has a new post talking about dependency injection today and proposes his own DIC solution (dependency injection container) "when Pimple is not enough".
Two months ago I wrote an article about Dependency Injection with PHP and Pimple. After the post I was speaking about it with a group of colleagues and someone threw a question: "What happens if your container grows up? Does Pimple scale well?" The answer is not so easy. Pimple is really simple and good for small projects, but it becomes a little mess when we need to scale.
His solution comes from the Symfony2 framework itself - using its DIC separately from the framework. He includes a configuration example and some simple classes that depend in each other. He also shows how to use imports in the config as well.
voice your opinion now!
pimple dic dependencyinjection tutorial symfony2
Anthony Ferrara: Object Scoping A Triste Against Service Containers
by Chris Cornutt August 23, 2012 @ 08:41:17
In his most recent post Anthony Ferrara talks about service containers, the cousin of dependency injection containers (DIC) that he argues aren't much better than global variables.
I am a firm believer that service containers are not a form of Dependency Injection, and are only slightly better than global variables. That led me to make a few comments that elicited a reply from two Fuel developers. That led to a rather interesting debate that just couldn't fit into 140 characters [on Twitter]... So I'm going to go into topics that are tightly related: variable scoping and service locators.
He starts by defining what global variables are (including the requisite Wikipedia definition) and how they're commonly use "everywhere" in the application, both set and read from. He contrasts this idea against a static variable from a class and redefines the scoping a bit when talking about objects and their properties.
So how does this apply to service locators (aka service containers or dependency injection containers)? Well, all state that's managed by a service locator immediately becomes global state to the objects that use the locator. So why is it all the rage? It's simple. It seems simple on the surface. If your object needs another dependency, there's no need to adjust how it's constructed, just pull it from the locator. Sounds great, right? Well, not quite.
He points out some of the main issues with using service locators namely difficulty in unit testing them, dependencies within the container, how it violates both the Law of Demeter and the Single Responsibility Principle as well as causing "hidden coupling" issues.
voice your opinion now!
object service container dependencyinjection opinion dic
PHPMaster.com: Managing Class Dependencies Dependency Injection, Service Locators & Factories, Pt 2
by Chris Cornutt June 28, 2012 @ 10:58:15
PHPMaster.com has posted the second part of Alejandro Gervasio's series looking at dependency injection, service locators and factories. In this new part of the series, he picks back up with his look at these patterns and how they can reduce your dependencies on things like "new" even more.
While it's fair to admit that factories do have a neat niche in a number of special use cases, I'm not so merciless as to condemn Service Locators and plain Dependency Injection to an unfair exile. In this final part we'll take a closer look at the implementation of these popular patterns so that you can pick up the one that best suits the need at hand.
He talks some about "class collaborators" as used in service locators and using it in his FileStorage example to find and use pre-created objects. He compares this method with a more simple dependency injection approach, noting that not only is it simpler to maintain but also can cause less overhead required for the DIC.
voice your opinion now!
class dependencies series dependencyinjection servicelocator
Chris Hartjes' Blog: DIC vs. Service Locator
by Chris Cornutt 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.
voice your opinion now!
dependencyinjection servicelocator testing difference
Henrik Bjørnskov's Blog: Stampie an in depth look
by Chris Cornutt December 15, 2011 @ 12:48:25
Henrik Bjørnskov has posted a bit of an in-depth look at Stampie, an abstraction library for sending emails from PHP applications via various service providers (like SendGrid and Mailchimp).
So what is Stampie. Stampie is a API wrapper for the most common email sending services. It provides a standard PHP Api to send emails. But mostly it is a project to test TDD and experiment with a couple of different things. Stampie is developed with Dependency Injection and therefore there is a lot of objects. At the start it can be quite cumbersome, but will make a lot of sense if you start to develop and add additional provider.
He includes a bit of sample code showing the sending of a message via the SendGrid API backend. Extending the system is simpler thanks to DI and the customizable MailerInterface object type. There's also an AdapterInterface object that can be used to redefine the HTTP connection interface the tool uses. He also points to the HBStampieBundle bundle for the Symfony2 framework that can make dropping it into your current SF2 application simpler.
voice your opinion now!
stampie email send tutorial dependencyinjection tool
|
Community Events
Don't see your event here? Let us know!
|