3 Replies Latest reply on Mar 25, 2008 10:20 AM by adrian.brock

    Missing class scope in InstantiateAction

    alesj

      I'm trying to apply IoC annotations to beans that only get their BeanInfo available in InstantiateAction.

       if (info == null)
       {
       info = configurator.getBeanInfo(object.getClass(), metaData.getAccessMode());
       context.setBeanInfo(info);
       // handle custom annotations
       applyAnnotations(context);
       }
      


      But I'm missing class scope (CommonLevels.CLASS) if the bean has no bean attribute defined in BeanMetaData, meaning it's gonna be constructed from some factory.
      Hence none of the class annotations are found in metadata.

      What's the way to update ScopeInfo/MetaData with class information?

        • 1. Re: Missing class scope in InstantiateAction
          alesj

           

          "alesj" wrote:

          What's the way to update ScopeInfo/MetaData with class information?


           ScopeInfo scopeInfo = context.getScopeInfo();
           ScopeKey scopeKey = new ScopeKey();
           for (Scope scope : scopeInfo.getScope().getScopes())
           scopeKey.addScope(scope);
           scopeKey.addScope(CommonLevels.CLASS, info.getClassInfo().getType());
           scopeInfo.setScope(scopeKey);
          
          


          OK, adding this after the BeanInfo has been set helps, since the metadata 'repairs' itself.
          But is this the right way? :-)

          • 2. Re: Missing class scope in InstantiateAction
            alesj

             

            "alesj" wrote:
            But is this the right way? :-)

            e.g. do we need some explicit MetaData removal from KernelMetaDataRepository before we change the scope key in ScopeInfo?

            • 3. Re: Missing class scope in InstantiateAction

               

              "alesj" wrote:
              "alesj" wrote:
              But is this the right way? :-)

              e.g. do we need some explicit MetaData removal from KernelMetaDataRepository before we change the scope key in ScopeInfo?


              You need to remove the old context before you change the key and re-register it.

              See the PreIntallAction or the KernelMetaDataRepository interface.