3 Replies Latest reply on May 30, 2008 1:28 PM by Pete Muir

    Lazy injection

    Adam Warski Master

      Hello,


      correct me if I'm wrong, but as I understand from what I've read in the manual and on the forum, bijection happens every time I invoke a method on a seam bean, that is, all fields with @In/@Out are written/read by reflection, yes?


      I don't know what are the experiences of other users, but in my applications I often use a pattern, where the majority of my beans are stateless beans, which have some other stateless beans injected, and occasionally a conversationally scoped bean.


      However, most methods of my stateless beans use only a subset of the injected beans - depending both on the method and on user data. That's why I started to wonder, if it wouldn't be reasonable to provide a lazy option for @In - that is, a bean would be searched in the contexts when a method on it would be invoked for the first time.


      There's also another problem, when invoking methods on seam beans when rendering a page, for example in a loop:



      <ui:repeat var="x" value="#{list}">
         #{myBean.myMethod(x)}
      </ui:repeat>




      Again, if I didn't miss something, bijection will happen every time myMethod is called, which in fact isn't really necessary, and in larger applications can make performance to decrease. So maybe it would be possible to inject proxies to the bean once, which would then, when invoked, search for the required bean in the contexts? That would save some writes of the fields. Of course, the search would happen only once on a method call, and after the method completes the state of the search should be reset. This still isn't the optimal performance, but I think it could do better then the current way. Or not? :)


      --
      Adam