I just finished up Mark Seemann’s opus, Dependency Injection in .NET. This book took a lot longer than I expected and I pretty much skipped his Part IV on various dependency injection frameworks (because I’m using Ninject, which he did not cover). This is a hefty tome at nearly 600 pages and Seemann goes into great detail on the topic of dependency injection.
My experience with dependency injection coming into the book was nil—in part because I’ve lived on the T-SQL side of the world for the past several years and probably haven’t written a non-trivial application in an object-oriented language this decade—and so I greatly appreciated the first part of the book. When Seemann described the wrong way of n-tier development, I immediately recognized it as the way I wrote code, and I kind of cringed. Seemann’s n-tier example included a data access layer, a business layer, and an application layer, and the wrong way had the app & business layers linked to the database layer, and the app layer linked to the business layer. This level of tight coupling has plenty of problems that I have experienced, but I simply didn’t know how to get around issue.
This is where parts 2 & 3 of the book come in. Throughout these parts, Seemann walks through “poor man’s DI,” manually writing code to perform dependency injection. He discusses what a composition root is, where to put the composition root (e.g., the Global.asax for ASP.NET MVC, or the Main method for a console application), how to build injectable objects, and he even spends some effort on refactoring older code to support dependency injection.
I can recommend this book, but at least for me, I needed supplementary resources to understand the topic better. It probably works great as a detailed manual for somebody familiar with the topic, but if you aren’t, be sure to check out videos on the topic and don’t be afraid to jump around a bit to understand where he’s going.