1.

What is the best way to inject dependency? Also, state the reason.

Answer»

There is no boundation for using a particular dependency INJECTION. But the recommended approach is - 

Setters are mostly recommended for optional dependencies injection, and constructor arguments are recommended for mandatory ONES. This is because constructor injection ENABLES the injection of VALUES into immutable FIELDS and enables reading them more easily.



Discussion

No Comment Found