explorers' club

explorations in dev, science, sci-fi, games, and other fun stuff!

Wanted: a better MVC paradigm with dependency injection (IoC)


First off, note the word “paradigm” rather than the more commonly used word “framework”.  As a self proclaimed pragmatist, the word paradigm seems more fitting in a world where no one shoe fits all.  Aren’t you tired of hearing the old debate of “which MVC framework is best”?  I am tired of the whole Cairngorm, PureMVC, Maté, Swiz, blah blah blah….  The dealo is that they all offer some strong solutions for common problems.  Certainly having NO MVC infrastructure in your application is a poor choice.  I have indeed been on a quest to find some solution in which I could utilize all the best from each library while leaving behind the bad.

Now I should preface this by saying I have no formal training in Computer Science.  I have been on a quest for a good dependency injection solution for a long time not knowing that was what it was called.  Besides, what’s in a name?  Does dependency injection or inversion of control really convey to the layperson the idea of wiring up an application?  I think I am fairly smart and I didn’t understand it even after reading Wikipedia on the subject.  To finish up here, let me compose a written goal(s) of what this post is all about and then I will dive into each point where applicable.  Some of these may be common knowledge but are still worth pointing out (pardon the “no-duh” points):

  • hereinafter the word “framework” will refer to existing MVC constructs such as Cairngorm, PureMVC, Maté, etc.
  • hereinafter the word “wiring” will refer to either an existing or proposed IoC/DI construct such as Spring Actionscript (formerly known as Prana), Maté’s Injector logic, etc.
  • User eXperience is hereinafter referred to as UX.  Any and all executable logic, whether triggered by user interaction or through subsequent data manipulation is considered UX.
  • application MVC constituents should be highly decoupled in the following manner:
    • view classes will be ignorant of any UX logic associated with their interactivity.  This will be accomplished either by a wiring mechanism similar to Maté’s EventHandlers in its EventMaps or PureMVC’s Mediators.
    • controller/command classes should function independently of one another such that particular UXs can be assembled via the wiring in a building block fashion.
    • data/model classes are to avoid ModelLocator implementations.  This will entail less {binding} and more verbose wiring logic.  This will accommodate modular application structures where Singletons are problematic.
  • Leveraging the event-driven nature of the Flash Player is ideal.
  • A solution that is Flex-agnostic is ideal.
  • A solution that can either take an XML or MXML map is ideal.  Having the option to “compile” the wiring is nice in that it maps much like the DI of Maté.

So there are a few goals I have in mind.  Obviously existing frameworks and wiring solutions have tackled some of these but I feel that they are mostly intrusive.  People use the term “boilerplate” code in reference to Cairngorm but I’d rather say that Cairngorm give you enough rope to hang yourself with.  People claim that PureMVC’s mediator implementation makes for more classes but I’d rather say that it is simply the price you pay for decoupling your views from your UX logic.  People say Maté is alot of smoke and mirrors but I’d rather say the idea of IoC is new to Flex developers that we haven’t readily accepted the fact that it works.

If you would like to see some of the work I am doing on this, you can check out some of the Mediator/Maté hybrid mashup stuff I am working on here – http://subversion.assembla.com/svn/as3mediatorlib/trunk.

Please sound off and if you are interested in working on a solution please contact me.  Thanks.


10 thoughts on “Wanted: a better MVC paradigm with dependency injection (IoC)

  1. hi, you totally have to try RobotLegs framework


    ioc, mediators, no singletons, events, …

  2. I’m interested at the perception that something like Cairngorm and Parsley would be mutually exclusive; they’re certainly not within Adobe. Alex Uhlmann and Tom Sugden will be talking about this in detail at MAX this year….

  3. I’ll second the pointer to Parsley 2. It’s a non-intrusive, Flex agnostic framework that satisfies the MVC requirements listed above and more. There’s a good developer manual too.

  4. @james, tom

    do either of you know if Parsley can attach its IoC/DI wiring into an existing project that might be utilizing (in a loose fashion) Cairngorm, Maté or PureMVC?

    I tend to subscribe to the idea that I’d rather buy a TV & VCR separately rather than buy one of those combination contraptions, if you know what I mean.

  5. @benoit

    I have checked out some of the docs and articles on RobotLegs but I have some concerns with the life span of the project. Do you know anyone that has used it in an enterprise application project?

    • @jwopitz

      I’ve used it on several projects (at least 2 of which would be considered “enterprise”) so far.

      That said, it’d probably be wise to wait for v1.0 before using it on a large project with a rapid turn-around time, as the API and usage patterns might change somewhat by then (but not too much).

      Community growth has been a little slow, but hopefully better documentation, more unit test coverage, tighter demos, and an official website are on the way.

      RobotLegs: Events, Commands and Mediation, that is all.

  6. If you want something that’s Enterprise ready check out Granite DS (http://www.graniteds.org/confluence/pages/viewpage.action?pageId=229378).

    Not only does it provide an excelent framework called TIDE it can also be used to replace BlazeDS or LCDS for server side communication. I’ve used it on two projects now and it’s been fantastic.

  7. Sorry about the bad hyperlink. Try this instead: http://www.graniteds.org

  8. For what it’s worth, RobotLegs is the first framework that has me excited to build with it. Most of the other frameworks have deal-breakers and I couldn’t find any of them in RL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s