Announcement Announcement Module
No announcement yet.
Simple, Auto DI (like Mate) - Spring N00b Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple, Auto DI (like Mate) - Spring N00b

    Hello ActionScript Springers!

    I'm not from a Java background, and don't know much about Java Spring, but I understand the concept of Dependency Injection and IOC containers. I've been struggling to figure out how to set up a mechanism similar to how the Injectors and ObjectBuilder tags work in Mate.

    What's nice about those tags is that you can set up a system that hooks into Event.ADDED_TO_STAGE (or FlexEvent.CREATION_COMPLETE) to do DI for view components as they are added to stage. Here is how I automatically wire up Mediators in Mate (shh.. don't tell Mate fanatics - they prefer Presenters to Mediators):

    <EventMap xmlns="blah" xmlns:mx="blah">
    	<ObjectBuilder id="controller" generator="{AppContoller}" registerTarget="true" />
    	<Injectors target="{AppContoller}">
    		<PropertyInjector targetKey="dispatcher" source="{scope.dispatcher}" />
    	<Injectors target="{PopWindow}">
    		<ObjectBuilder generator="{PopWindowMediator}" registerTarget="true" cache="none">
    			<Properties view="{event.injectorTarget}" dispatcher="{scope.dispatcher}" />
    	<Injectors target="{PopWindowMediator}">
    		<PropertyInjector targetKey="dispatcher" source="{scope.dispatcher}" />
    		<PropertyInjector targetKey="controller" source="{AppContoller}" />
    Whenever a PopWindow is added to stage, a new PopWindowMediator is created that has a reference to the PopWindow injected into it (and references to a global AppController and IEventDispatcher).

    Is such a thing possible with Spring ActionScript? If so, how might I go about it?

    Many thanks!

  • #2

    autowiring view components is not in the framework at this moment, but it we're using it with custom code at this moment. In fact, the only thing I need to do is generalize that code and plug it in to the FlexXMLApplicationContext class.

    I have written about this on my blog ( Check the last part on Presentation Models and Autowiring. Basically you can inject every property you define as autowired with the [Autowired] metadata. The custom code to do the autowiring is also provided in the blog post.

    Looking forward to hearing your thoughts.



    • #3
      Hi Christophe,

      That's pretty cool! Thanks for the response and link. I shall need to figure out how ActionScript Spring is generally used in order to understand the code in your post, but it looks pretty handy.

      On that note, I have been having a little trouble finding good documentation on getting started with AS Spring. I'm sure there is a lot of useful info on your blog, but it's quite spread out, and one can't be sure if the older posts are still valid etc.

      If I do manage to figure it out I'll definitely write an Intro to ActionScript Spring tutorial to help others, like myself, who are new to Dependency Injection and IOC.

      All the best,


      • #4
        docs are getting pretty good

        hi i just found the documentation on

        pretty good already!

        the lacking of good docs was the biggest drawback of this excellent framework. glad it's being addressed

        thanx folks!