Dependency Injection is a design pattern that removes the dependency of programs from each other and gets the information from the XML file. The benefit of Dependency Injection is that it combines Code comfortably and facilitates Unit Testing.
We can inject objects using Setter. Two basic structures that we will use in XML are important in the injection method with Setter. These structures
- bean: The object to inject. We specify the ID and Path of our object.
- Primitive types for which we will specify property:Setter values. For example: (int id,String name, etc.)
XML file
Constructor Injection, In this method, we produce a constructor of our primitive definitions or Linked objects instead of a setter methods in our Object and specify it in our XML file. What is important in this method is our concept.
- constructor-arg value: The arguments and values of the constructor we created in our object.
XML file