0 Replies Latest reply on Mar 4, 2009 5:20 PM by Guillaume Jeudy

    Outjection and Seam interceptors

    Guillaume Jeudy Master

      Hi,


      I have a case where several Seam components implement the same interface. Another loosely coupled Seam component gets injected likeso.


      @Name("foo")
      public class Foo implements ICommonInterface {
       
        @In(required=false)
        @Out(required=false)
        private AnotherBijectedField anotherField;
      
        @Out
        private ICommonInterface commonInterface = this;
      }
      
      @Name("bar")
      public class Bar implements ICommonInterface {
      
        @In(required=false)
        @Out(required=false)
        private SomeBijectedField field;
      
        @Out
        private ICommonInterface commonInterface = this;
      }
      
      @Name("looselyCoupledBean")
      public class LooselyCoupledBean {
      
        @In
        private ICommonInterface commonInterface;
      }
      



      The problem I see is that injected commonInterface object is not properly initialized (bijected fields are not set) because it seems I have access to the variable outjected in the context which doesn't benefit of any Seam interception goodness.


      Is there an alternative in using

      @Out private B b = this;

      for such a case? Or is that an anti-pattern? I'm considering using some kind of Seam Factory instead:


      @Name("factoryManager")
      public class CommonInterfaceFactory {
      
         @In
         private String commonInterfaceBeanName;
      
         @Factory("commonInterface")
         public ICommonInterface create() {
                return Component.getInstance(commonInterfaceBeanName);
         }
      }
      


      Then in Foo and Bar beans I need to outject commonInterfaceBeanName by reading the @Name value attribute... That works by the way.


      I'd be interested to hear what others have done to tackle this issue.


      Thanks,
      -Guillaume