Here you define the OrderService and have the StockService injected (hence
the name of the pattern). A so-called container (application context) reads this
configuration file, resolves the dependencies and puts together the objects.
When the objects are ready, all the dependencies are already injected.
Suppose Order Service needs Stock service as dependency.
Solution
The OrderService simply needs to define a setter method:
Then in an XML file you can define the OrderService like this:
Here you define the OrderService and have the StockService injected (hence the name of the pattern). A so-called container (application context) reads this configuration file, resolves the dependencies and puts together the objects. When the objects are ready, all the dependencies are already injected.