• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency Injection DI concept

 
Juggy Obhi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I searched and read almost every thread on DI and Dependency Injection. I learned a lot with all the information but i still have doubts.

If we have an EJB like:




We can get this EJB injected into any Managed Component like Servlets and other EJB's using DI



AND




This is my understanding of Dependency Injection.

I was reading MZ Notes section "Annotations for Environment Entries" i got confused with the concept mentioned there which says:



By Default, the name of the field is combined with name of the class in which the annotation is used and is used directly as the name in the bean's naming context.


According to this

@EJB MyEJBBusinessInterface abcDI; will search for java:comp/env/com.foo.abc.MyABC/abcDI

AND

@EJB MyEJBBusinessInterface xyzDI; will search for java:comp/env/com.foo.xyz.MyXYZ/xyzDI

so to me these are two different references in the bean's naming context. I want to understand how MyEJB (the bean to be injected) is available to both?

And when we declare this bean



This bean is supposed to be available/placed in the JNDI(Global) or Bean's Naming Context(java:comp/env) (I would be very thankful if some one can explain where exactly) by the container for sure because then only DI can work.

I want to know is this Automatic? I mean just use @Stateless annotation and its done ?? is it??

Thanks in Advance.

[ October 14, 2008: Message edited by: Juggy Obhi ]
[ October 14, 2008: Message edited by: Juggy Obhi ]
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use @EJB(name="nameOfEjb") MyEJBBusinessInterface xyzDI
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic