Announcement Announcement Module
Collapse
No announcement yet.
Problems while autowiring to from child to parent context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems while autowiring to from child to parent context

    Hello everyone,

    we are creating a composite application framework on the top of Spring AS "building blocks" (we do not use Flex modules but our own modular architecture).

    The top-level application defines an app context and loads "modules" defined locally (into the same SWF artifact) or remotely, each of them defining a child context. The issue we are facing is that we have not been able to autowire properties of objects created from the children contexts to object instances provided by the top-level one (seems that candidates are only searched into the objectDefinitions from the children). This forces to wire collaborators from parent context using refs.

    I could be wrong, but I think that the Java implementation of Spring allows autowiring from child to parent. Is it a bug, are we doing something wrong or is there particular reasons to forbid such practices ? If so, could anyone suggest some sort of approach to avoid using refs ?

    Many thanks,
    Jef

  • #2
    Spring doesn't allow that... The child can access the parent, the parent knows nothing about the childeren.

    Comment


    • #3
      Hi Martin,

      thanks for answering.

      Accessing the parent from the child is exactly what I'm trying to do. To clarify, if I declare an object in the parent context :

      Code:
      <object id="a" class="tld.org.projet.A"/>
      and refer to the object A in the child context :

      Code:
      <object id="b" class="tld.org.projet.B">
          <property name="refToA" ref="a"/>
      </object>
      ... everything works fine. Using the same declaration in the parent context and trying to autowire the refToA property :

      Code:
      public class B
      {
          [Autowired]
          public var refToA : A;
      }
      ... Spring complains it does not find any candidate for AW. As B has been created by the object factory corresponding to the child context the autowiring attempt is performed at the child level.

      Comment


      • #4
        might be a bug, not sure

        Hey Jeff,

        it seems like a bug from your description, can you post a small example project that demonstrates the problem? That we'll be able to more easily determine where things go wrong.

        thanks in advance,

        Roland

        Comment


        • #5
          Hey Roland,

          sorry for late answer. Here you may find three variants of the same project :
          - in the first case, the collaborator is injected using autowiring, there is a single context : works properly ;
          - in the second case, the collaborator is injected autowiring, but this time there are a child and a parent context : fails to find a candidate for autowiring ;
          - in the third case, there are two contexts but the collaborator is not autowired but injected using a reference : works properly.

          Hope this helps,
          Jef.

          Comment


          • #6
            thx

            Hey Jef,

            I'll try and have a look at your examples asap, right now I'm a bit swamped at the office but I promise I'll have a look later this week. I suspect that the issue lies with autowiring by type which doesn't take a potential parent context in account, but I'm not sure, I'll have to investigate.
            Thank you for taking the time to post the examples!

            cheers,

            Roland

            Comment


            • #7
              Hey Roland,

              the intuition about this issue is right. I created a patch for the DefaultAutowireProcessor class.

              I add to use the ugly
              Code:
              ( factory is IApplicationContext )
              expression in line 428 because the IObjectFactory interface does not expose the "parent" property (it seems that it was the case but for some reason the code has been commented out at some time, see there).

              Thanks for your answer,
              Jef.

              Comment


              • #8
                ...

                Hey Jef,

                yea, I had noticed the commenting out of the parent property in that particular interface earlier, in the trunk version its back, so in version 1.0 it'll be back I'll review your patch asap, cheers!

                Roland

                Comment


                • #9
                  Roland,

                  I guess i'll eagerly wait for the 1.0 release.

                  Cheers !
                  Jef

                  Comment


                  • #10
                    I've implemented the autowiring by type which takes a parent factory into account as well, I've did it in a slightly different way then your patch though.

                    Version 1.0 will be released either today or somewhere this weekend, I'm sifting through the last tidbits at the moment. But it'll be ready real soon now

                    cheers,

                    Roland

                    Comment


                    • #11
                      Roland,

                      I've seen that if there is no candidate found you now delegate to the aw processor associated with the parent factory, much smarter.

                      I've been working for years with the Java implementation, so massive thanks to the development team/community for this great AS project (and for the upcoming release). I'd be glad to contribute if needed.

                      Jef.

                      Comment


                      • #12
                        thanx

                        Hey Jef,

                        thank you for the kind words, and we are ALWAYS on the look out for more contributors. If you're serious about joining the team then get in touch with me after the version 1.0 release and we can discuss further what you can bring to the table.

                        thanks!

                        cheers,

                        Roland

                        Comment


                        • #13
                          Hi Roland,

                          I checked the 1.0 release which works like a charm. I'm a bit overhelmed with work so I'll PM you during the weekend.

                          Many thanks.
                          Jef

                          Comment

                          Working...
                          X