20Dependency 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.