Announcement Announcement Module
Collapse
No announcement yet.
Simple, Auto DI (like Mate) - Spring N00b Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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):

    Code:
    <EventMap xmlns="blah" xmlns:mx="blah">
    	
    	<ObjectBuilder id="controller" generator="{AppContoller}" registerTarget="true" />
    	
    	<Injectors target="{AppContoller}">
    		<PropertyInjector targetKey="dispatcher" source="{scope.dispatcher}" />
    	</Injectors>
    	
    	<Injectors target="{PopWindow}">
    		<ObjectBuilder generator="{PopWindowMediator}" registerTarget="true" cache="none">
    			<Properties view="{event.injectorTarget}" dispatcher="{scope.dispatcher}" />
    		</ObjectBuilder>
    	</Injectors>
    	
    	<Injectors target="{PopWindowMediator}">
    		<PropertyInjector targetKey="dispatcher" source="{scope.dispatcher}" />
    		<PropertyInjector targetKey="controller" source="{AppContoller}" />
    	</Injectors>
    	
    </EventMap>
    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
    Hi,

    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 (http://www.herrodius.com/blog/158). 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.

    regards,
    Christophe

    Comment


    • #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,
      Darscan

      Comment


      • #4
        docs are getting pretty good

        hi i just found the documentation on
        http://www.springactionscript.org/do...ionscript.html

        pretty good already!

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

        thanx folks!

        Comment

        Working...
        X