20Dependency Injection

WHAT IS DEPENDENCY INJECTION?

Faster development cycles demand unit tests and better updatability. Making some code changes should not result in errors in unexpected places. Creating more modular applications where dependencies are reduced helps with that.

Dependency injection (DI) allows injection dependencies from the outside of a class, thus the class where the dependency is injected only needs to know about a contract (usually a C# interface). The class can be independent of the creation of its objects.

Dependency injection allows for easier unit tests. With the unit test, only a specific class needs testing, and the dependencies needed can be replaced by a special ...

Get Professional C# 7 and .NET Core 2.0, 7th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.