What is Dependency Injection?
=======================================
-> Dependency Injection (DI) is a design pattern that removes the dependency from the programming code so that it can be easy to manage and test the application.
-> Dependency Injection makes our programming code loosely coupled.
-> In such case we provide the information from the external source such as XML file.
-> It makes our code loosely coupled and easier for testing.
-> DI is all about objects and their dependencies.
-> In Spring frameowork, Dependency Injection (DI) design pattern is used to define the object dependencies between each other.
-> It is a process where objects are defining their dependencies and other objects work with them either constructor arguments or properties .
-> There are 2 widely used types: 1. Setter Injection, and 2. Constructor Injection
-> If we configure both setter injection and constructor injection on bean property the values given by setter injection will remain as final values of injection
because setter(-) method executes after constructor executes and overrides the values injected by the constructor execution or injection.
-> When we go for Setter Injection or when we go for Constructor Injection?
====================================
-> At the time of creating our target class object, the dependent objects are injected or instantiated through Constructor Injection.
-> Whereas in Setter Injection dependent objects are not injected or instantiated while creating the target class object;
those will be injected after the target class has been instantiated by calling the setter on the target object.
-> If bean class contains only one property or if all the property of bean class should participate in dependency injection then
we should go for constructor injection because constructor injection is very faster than setter injection.
-> If bean class contains more than one property and there is no need of making all properties (means optional to inject) are
participating in dependency injection, then we should go for setter injection. So it is bit delayed injection.
-> Constructor Injection doesn’t support cyclic dependency.
-> Whereas Setter injection supports cyclic or circular dependency injection.
-> To perform constructor injection on n properties in all angles, n! Constructors are required.
-> Whereas to perform setter injection on n properties in all angles “n-setter” methods are required.
-> To perform constructor injection we will use <constructor-arg>.
-> Whereas to perform setter injection we will use <property> tag.
-> Spring supports dependency injection on the following properties:
a. Simple properties (primitive data types, String)
b. Reference or Object type properties
c. Collection properties (Array, List, Set, Map, Properties, and etc...)
=======================================
-> Dependency Injection (DI) is a design pattern that removes the dependency from the programming code so that it can be easy to manage and test the application.
-> Dependency Injection makes our programming code loosely coupled.
-> In such case we provide the information from the external source such as XML file.
-> It makes our code loosely coupled and easier for testing.
-> DI is all about objects and their dependencies.
-> In Spring frameowork, Dependency Injection (DI) design pattern is used to define the object dependencies between each other.
-> It is a process where objects are defining their dependencies and other objects work with them either constructor arguments or properties .
-> There are 2 widely used types: 1. Setter Injection, and 2. Constructor Injection
-> If we configure both setter injection and constructor injection on bean property the values given by setter injection will remain as final values of injection
because setter(-) method executes after constructor executes and overrides the values injected by the constructor execution or injection.
-> When we go for Setter Injection or when we go for Constructor Injection?
====================================
-> At the time of creating our target class object, the dependent objects are injected or instantiated through Constructor Injection.
-> Whereas in Setter Injection dependent objects are not injected or instantiated while creating the target class object;
those will be injected after the target class has been instantiated by calling the setter on the target object.
-> If bean class contains only one property or if all the property of bean class should participate in dependency injection then
we should go for constructor injection because constructor injection is very faster than setter injection.
-> If bean class contains more than one property and there is no need of making all properties (means optional to inject) are
participating in dependency injection, then we should go for setter injection. So it is bit delayed injection.
-> Constructor Injection doesn’t support cyclic dependency.
-> Whereas Setter injection supports cyclic or circular dependency injection.
-> To perform constructor injection on n properties in all angles, n! Constructors are required.
-> Whereas to perform setter injection on n properties in all angles “n-setter” methods are required.
-> To perform constructor injection we will use <constructor-arg>.
-> Whereas to perform setter injection we will use <property> tag.
-> Spring supports dependency injection on the following properties:
a. Simple properties (primitive data types, String)
b. Reference or Object type properties
c. Collection properties (Array, List, Set, Map, Properties, and etc...)
Comments
Post a Comment