Understanding Dependency Injection by Example
Dependency injection (DI) is a software design pattern that exists in every modern architecture. However, you may wonder how this pattern found its way into the second chapter of a test-driven development (TDD)-focused book.
DI is a pattern that has several benefits that we are going to discover throughout the book, though the core benefit is that DI opens an application for unit testing. We cannot exercise unit testing without a solid understanding of this pattern, and if we cannot unit test, by virtue, we cannot practice TDD. Considering this, DI understanding forms the foundation of Section 1, Getting Started and Basics, and Part 2, Building an Application with TDD, which explains the early introduction.
We will build an application and then modify it to support DI while learning the concepts, but the ideas in this chapter will be repeated and exercised throughout this book.
In this chapter, you will be exploring these topics...