Explain why constructor inject is better than other options [duplicate]
Dependency Injection: Everything You Need to Know
Microsoft - Dependency Injection - Overview
Do not hard-coded dependencies for the following reasons:
- To replace MessageWriter with a different implementation, the Worker class must be modified.
- If MessageWriter has dependencies, they must also be configured by the Worker class. In a large project with multiple classes depending on MessageWriter, the configuration code becomes scattered across the app.
- This implementation is difficult to unit test. The app should use a mock or stub MessageWriter class, which isn’t possible with this approach.
My Issue
perplexity – What is dependency injection, how does this idea coming, what is the background and scenerio