• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dependency injection

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any body tell me what actually Dependency injection is ?
How could we implement it in JSF ?

Thanks,
S
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two ways to link objects. One is to go find them and use them, the other is to have an external agency find them and feed them to you.

The second option is dependency injection, and it's done using the managed-property stanzas in the faces-config file, which name an object and the property within the target managed bean that is to be set to the named object.

The advantage of dependency injection is that it makes stuff more reusable and removes interdependencies from application code. As an example, I have an app whose production version sends lots of emails. I don't want a bunch of test emails cluttering up my servers, so I inject a dummy emailer module into the app that writes the emails out to the server log file instead of actually mailing them. When I'm ready for production, I'll replace it with the production emailer. No program logic changes are required, just an adjustment to faces-config.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic