This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 15964
    
  19

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dependency injection
 
Similar Threads
difference between IOC and Dependency Injection
Pluggable Components
passing beans..
What's the difference between 'Inversion of control' and 'Dependency injection'?
Dependency Injection & Testability