Global singletons
One of the biggest pains was undoubtedly the use of global public singletons. At first glance, they seemed to make the code more concise, but they were actually making it much harder for us to test.
The use of init() functions to create variables meant that we either had to use the live versions (that is, on the database) or had to monkey patch the globals, which led to potential data races.
We started off with two public globals (config and logger) and one private global (the database connection pool). In Chapter 5, Dependency Injection with Monkey Patching, we used monkey patching to give us the ability to test the code that relied on the database connection pool singleton.
In Chapter 10, Off-the-Shelf Injection, we finally ...
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