Flex coders, does Dependency Injection pay off?
ActionScript, Flex, Inversion of Control, Prana Add commentsNiclas Nilsson, recently wrote a post on InfoQ about the benefits or the lack of benefits of using Dependency Injection (DI). In the post he summarizes a discussion that spanned multiple blogs, all with their own pros or cons of using DI. It is an interesting read to say the least. If you’re new to DI or even if you’re familiar with it and are pro or con, you will certainly pick up new motivations and ideas.
Bringing this into a Flex context, I was wondering how many Flex developers are actually using DI. Since I’m developing Prana, an Inversion of Control (IoC) container for ActionScript 3.0, and have talked about it with several people (mostly Flex developers), I know that DI and IoC are concepts that are still pretty unknown to many of them. There are also lots of misconceptions like: DI is only good for mocking while Unit Testing, it costs more time/money, DI is all about XML, it’s too complicated, it stimulates bad application design, …
So I’d like to hear from you. Are you as a (Flex) developer using any form of DI or IoC? Is it DI-by-hand or are you using any container (which one)? If you’re not using it, is that because you haven’t figured out what it is or are you convinced that it does not serve your needs? Feel free to share your thoughts, opinions and experience.
Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
Christophe Herreman is a software developer living in Belgium. He's working on high-end Flex and AIR solutions at 
December 16th, 2007 at 7:46 pm
Since DI comes so natural to the MXML syntax I wouldn’t be surprised if many Flex coders just defaulted to DI without knowing that it’s DI.
As for those not designing in a DI manner I would write most of it down to the tendency of inexperienced programmers to overcomplicate things.
That is also my own path to DI, when I started programming I overcomplicated things, but as my experience have grown I tend to solve things in a more and more elegant manner, and I consider DI to be a very elegant solution to architecture.
December 16th, 2007 at 10:01 pm
Good points Theo. I can certainly relate with you on the fact that the ‘aha’ moment on DI comes as you gain more programming experience.
January 2nd, 2008 at 1:21 pm
I’ve been using DI in AS3 and Flex since Flex 2 was released as I got tired of instantiating and wiring up class instances. I took a liking to the PicoContainer API and used it as inspiration for the DI library I’ve released.
For me the time taken to write the library has been well worth it for the time saved when implementing an app thanks to being able to configure and change implementations in one place instead of all through an app.
Other features like lazy instantiation, and cached instances (singletons) are all helpful as I can keep the classes relevant to what they are doing and not pollute them with class instance creation or singleton implementation details.
In order for ideas like DI to gain momentum in the Flash community they need advocacy and education. Its up to people like us to make that happen.
January 13th, 2008 at 12:50 pm
I am currently reading through the Spring documentation. They have implemented the DI (Dependency Injection) and IoC (Inversion of Control) perfectly.
As far as I know the knowledge about these two patterns within the ActionScript community is very low. I however think that ActionScript would benefit greatly from a Spring like framework.
Greetz Erik
January 13th, 2008 at 12:51 pm
Haha, after writing this reply I registered to your newsfeed and noticed the article named ‘Porting the Spring IoC core to Prana’.
Cheers Erik