Summary
In this chapter, we have examined DI with method injection, perhaps the most ubiquitous of all forms of DI.
When it comes to extracting dependencies from existing code, for the purposes of testing, it might be the method that first comes to mind. Please be careful with this, we do not want to introduce test-induced damage.
Adding parameters to an exported API function for the sole purpose of testing undoubtedly damages UX code. Thankfully, there are some tricks available to us to avoid damaging our API. We can define member functions that only exist in test code. We can also use Just-In-Time (JIT) dependency injection, which we will examine in Chapter 9, Just-in-Time Dependency Injection.
In this chapter, we have looked at the fantastic ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access