• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency injection

 
S Majumder
Ranch Hand
Posts: 349
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any body tell me what actually Dependency injection is ?
How could we implement it in JSF ?

Thanks,
S
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic