Collection and sharing of, interview questions and answers asked in various interviews, faqs and articles.....
What are the different types of IoC dependencyinjection?
Types of IoC are:
Constructor-based dependency injection: Constructor-based DI is accomplished when
the container invokes a class constructor with a number of arguments, each representing a
dependency on other class.
Setter-based dependency injection: Setter-based DI is accomplished by the container
calling setter methods on your beans after invoking a no-argument constructor or noargument
static factory method to instantiate your bean.
Which DI would you suggest Constructor-based or setter-based DI?
Since you can mix both, Constructor- and Setter-based DI, it is a good rule of thumb to use
constructor arguments for mandatory dependencies and setters for optional dependencies. Note
that the use of a @Required annotation on a setter can be used to make setters required
dependencies
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment