wood burning stoves
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
JavaRanch » Java Forums » Java » JSF
Bookmark "Dependency injection" Watch "Dependency injection" New topic

Dependency injection

S Majumder
Ranch Hand

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

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

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.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link: http://aspose.com/file-tools
subject: Dependency injection
It's not a secret anymore!