Announcement Announcement Module
No announcement yet.
Autowiring works in mxml, but not is as Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowiring works in mxml, but not is as


    as the title says, I have a problem using autowiring in an Actionscript class (mxml works).

    What I did:

    // TODO: Autowiring does not work (this is an AS class)!
        public var dateFormatter:DateFormatter; 
    // Workaround: public var dateFormatter:DateFormatter = MyApp(ApplicationUtils.application).applicationContext.getObject("dateFormatter");
    My context.mxml:
      <Object id="dateFormatter" clazz="{DateFormatter}" >
        <Property name="formatString" value="D MMMM YYYY, H:N" />
      <Object id="autowiringStageProcessor" clazz="{DefaultAutowiringStageProcessor}"/>
    Part of MyApp.mxml:
    private function loadApplicationContext():void {
            applicationContext = new MXMLApplicationContext(context);
            applicationContext.addEventListener(Event.COMPLETE, applicationContext_completeHandler);
    Any Ideas? Thanks for your help!

  • #2

    Is the actionscript class that contains the [Autowired] annotation instantiated by the application context? If not, then Spring Actionscript won't be able to inject anything. In MXML this works because of Spring Actionscript can detect these instances when they're being added to the stage.
    Regular classes will have to be instantiated by the container, either by having an object definition or by invoking applicationContext.createInstance(ClassName);




    • #3
      OK, thanks!!!
      That is the problem. Makes sense.

      Two questions:

      1. In Java (Spring) would this no problem!? Or is it necessary that a Java class is annotated with @Component (@Controller, @Repository, @Service). Or do such classes need to be instantiated by the container as well (which is usually the case)?

      2. Isn't it possible to possible to annotate such an AS-class, which then dispatches a corresponding event so that the instantiation can be recognized?

      Thanks again in advance.


      • #4
        no such mechanism

        Hi there,

        to answer your questions:

        1. I can't say for sure whether it is possible in Java Spring to detect an arbitrary class instantiation and intercept this by the IoC container. Using AOP its definitely possible, but then only for property and method injection. In Actionscript its simply not possible though.
        N.B. In the upcoming version 1.1 we will however be supporting [Component] annotations though, which will mean that object definitions will be possible to be defined completely in metadata.

        2. A custom event mechanism could made possible for something like this, although it would require every class that needs to be injected to dispatch these events manually. Which will also mean that your classes will receive a dependency on the SpringAS framework. Namely the framework specific events and the EventBus (since the EventBus will naturally be sued to dispatch such events).
        I have no idea if such a mechanism would be desirable, I can think about an implementation of course, but I'm not sure if this is something that is in high demand.
        Anyone else on the forum that has thoughts on this?




        • #5
          Ok, thanks for your answers and your effort!