Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism & DI

 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Business Layer


Client Layer



Doubt
Since I am using interface in client layer; how would I archive the following;



I would appreciate your help.

Regards,
Sanjeev.
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
you have to deploy the two beans (with a different jndi name), then add two @EJB injections which points to the two different names.
But if the choice between the two ejbs is decided at deployment time, you can play with xml stuff...
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agrees to deploy 2 beans,
And client side needs 2 DI (which means injection of two EJB objects at client side)

But if I use lookup (initCtx.lookup) based on condition; then only one EJB would be injected (client would be bound / have only one EJB) and can avoid second EJB, which is not needed.

Am I correct?


Thanks.
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you have no EJB injected at all.
In fact, you simply access your ejb using jndi instead of using injection.
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant using DI client would have 2 object

Using lookup client would have only 1 object, since lookup can be kept under condition.

what I am trying to understand is that lookup process has advantage in this case compare to DI.

Am I correct?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic