Explain why constructor inject is better than other options [duplicate]
This question already has an answer here: Setter DI vs. Constructor DI in Spring? 7 answers In a Pro Spring 3 Book, Chapter 4 - Introduction IOC and DI in Spring - Page 59, In "Setter Injection vs. Constructor Injection" section, a paragraph says Spring included, provide a mechanism for ensuring that all dependencies are defined when you use Setter Injection, but by using Constructor Injection, you assert the requirement for the dependency in a container-agnostic manner" Could you explain with examples A class that takes a required dependency as a constructor argument can only be instantiated