1 Reply Latest reply on Apr 26, 2010 12:24 PM by pmuir

    using @Inject vs. @EJB to inject session bean

    asookazian

      My question is along the lines of this one: http://forums.java.net/jive/thread.jspa?threadID=69238


      I noticed in the weld-translator app that in the TextTranslator class below:


      public class TextTranslator implements Serializable {
         private SentenceParser sentenceParser;
         @EJB private Translator translator;
         @Inject public TextTranslator(SentenceParser sentenceParser) {
            this.sentenceParser = sentenceParser;
         }
         public String translate(String text) {
            StringBuilder sb = new StringBuilder();
            for (String sentence: sentenceParser.parse(text)) {
               sb.append(translator.translate(sentence)).append(". ");
            }
            return sb.toString().trim();
         }
      }
      



      there is usage of both @EJB and @Inject.  One is a session bean, the other is a JavaBean.  I replaced the @EJB with @Inject and everything still works fine apparently.


      (Yes, I did read the weld-reference doc this time, specifically section 7.4)


      So what is the best practice here in terms of injecting session beans?  It would be nice to use only @Inject for everything similar to what we currently do with @In in Seam 2.x.