2 Replies Latest reply on Dec 28, 2009 6:04 PM by Arbi Sookazian

    injection using In vs. EJB

    Arbi Sookazian Master

      Are there are significant problems or disadvantages with using @EJB to inject instead of @In other than @EJB is a static injection?  I've always used @In in my Seam apps but I've hit a codebase which is using @EJB to inject the local interface.  thx.

        • 1. Re: injection using In vs. EJB
          Arbi Sookazian Master

          answer from 2.2.0.GA ref doc:



          But what about @EJB? It's true that you can inject one EJB into another using @EJB. However,
          by doing so, you are injecting the actual EJB reference rather than the Seam EJB component
          instance. In this case, some Seam features will work, while others won't. That's because Seam's
          interceptor is invoked on any method call to an EJB component. But that only invokes Seam's
          server-side interceptor chain. What you lose is Seam's state management and Seam's client-side
          interceptor chain. Client-side interceptors handle concerns such as security and concurrency.
          Also, when injecting a SFSB, there is no guarantee that you will get the SFSB bound to the active
          session or conversation, whatever the case may be. Thus, you definitely want to inject the Seam
          EJB component using @In.
          • 2. Re: injection using In vs. EJB
            Arbi Sookazian Master

            After further research, it's possible to define a class as a Seam component in components.xml.


            Ex:


            <component name="foo" class="org.foo.bar.Foo"/>



            This way, if you have a DAO or service class that is shared with another non-Seam app and we can't add the @Name annotation to the class b/c it's not guaranteed the class will live in a Seam container, then you simply make the class a Seam component in the components.xml as shown above.


            I think the only real legitimate use of @EJB is when we must inject a remote EJB instance.  Is this correct? Plz verify...