Home Constructor Injection First | SE Princple
Post
Cancel

Constructor Injection First | SE Princple

Explain why constructor inject is better than other options [duplicate]

A Comprehensive Guide to Best Practices and Common Scenarios Using Dependency Injection in .NET 8 with C#10

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

This post is licensed under CC BY 4.0 by the author.

新工作, 新公寓

你好,温哥华