wood burning stoves 2.0*
The moose likes JSF and the fly likes Dependency injection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Dependency injection" Watch "Dependency injection" New topic
Author

Dependency injection

S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Can any body tell me what actually Dependency injection is ?
How could we implement it in JSF ?

Thanks,
S
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
 
subject: Dependency injection