This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes Setter Injection V/S Constructor Injection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Setter Injection V/S Constructor Injection" Watch "Setter Injection V/S Constructor Injection" New topic
Author

Setter Injection V/S Constructor Injection

Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
I would like to know when we should be using Setter Injection?


And, in which case, we should use Constructor Injection?
Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 811
    
  38

This question has been asked many many many times over the years. A little research would give you loads of reading material.

On this forum:
http://www.coderanch.com/forums/jforum?module=search&action=search&forum_id=-1&search_keywords=setter+injection+constructor+injection&match_type=all&search_in=ALL&forum=96&sort_by=time&sort_dir=DESC&search_date=ALL&member_number=&member_first_name=&member_last_name=&member_match_type=memberPosted

On the wider internet:
http://lmgtfy.com/?q=constructor+injection+vs+setter+injection


Tim Driven Development
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Setter Injection V/S Constructor Injection
 
Similar Threads
DI Queries
DI - Constructor injection / Setter Injection ?
why we do not need getter method for variable ?
Setter based vs. Constructor based injection
I need help - basic stuff (I think)