views:

1789

answers:

11

It seems like there are very few books (yes, I read books) on Dependency Injection. The Amazon tag for "dependency injection" lists only a few titles, and all of them are specifically about Spring for Java.

Are there any books out there that cover DI/IoC in general? Or any that include a survey of multiple DI frameworks? Or any that cover .NET in lieu of or in addition to Java?

Or do we have to rely on this newfangled interweb instead of dead trees...

+6  A: 

I'd be very wary of a book on DI, because there's just not that much to say on the topic. It makes for a good chapter in a Best Practices or Patterns book, but I can't see getting a book out of it.

Avdi
Absolutely. There is no real point to read a book about something you could be writing in less than a day yourself (The container I mean).
Tigraine
@Tigraine - naturally. Then you just need to get it to production quality...
Thorbjørn Ravn Andersen
Oh god yes. +1.
Rob Lachlan
+5  A: 

As far as I can tell, there are no books on DI/IoC in general, but the classic write up on this is by Martin Fowler.

If you had to investigate a specific DI/IoC framework and get an explanation of DI/IoC as a side effect, I would recommend the 1st chapter of Spring in Action or watch Bob Lee's explanation on video.

Alan
+4  A: 

Jimmy Nilson's book covers the concept with a focus on the DotNet environment (Applying Domain-Driven Design and Patterns), and Martin Fowler's Bliki covers the idea more generally, but it's not really complicated enough to warrant an entire book.

As for a survey of different alternatives, I don't think any books cover more than a couple of options.

For DotNet, you probably want to investigate Spring.net, StructureMap, Ninject (and I'm sure there are others).

JasonTrue
+1  A: 

From Apress came the 1st book on Dependency Inject -- http://apress.com/book/view/1590599977 -- Google Guice: Agile Lightweight Dependency Injection Framework

Of course, there are other books which talk about Spring's Dependency Injection --
1) Spring in Action by Manning
2) Professional Java development with Spring Framework (http://www.amazon.com/Professional-Java-Development-Spring-Framework/dp/0764574833) -- which is a lil dated now BUT still a decent book for understanding DI

anjanb
A: 
Rinat Abdullin
+9  A: 

there is a whole 375 pages book on multiple DI frameworks, by Dhanji R. Prasanna covering java, ruby, c# but only as a preview in ebook format, it will be published printed in feb 2009.

Andreas Petersson
**Update:** That book doesn't actually cover C# and Ruby. They must have dropped these languages in favor of Java. (The cover text has changed accordingly.) However, there's another upcoming book by the same publisher, _Dependency Injection in .NET_ (see http://manning.com/seemann/).
stakx
+1  A: 

This doesn't answer the question directly, but Jim Weirich has a good write up on Dependency Injection. It's titled Dependecy Injection in Ruby, but it explains the underlying concepts well.

Consequently, Jim Weirich also sums up Dependency Injection in One Sentence.

If you had one sentence to explain to a Java programmer why Dependency Injection is rarely necessary in Ruby, what would it be?

Dependency injection provides vital flexibility in Java [or .NET] and unneeded overhead in Ruby [et al].

While I understand this answer could be seen as off-topic or flamebait, the intention is really meant to provoke thought on the subject, nothing more.

Ryan McGeary
Talking in oneliners is just dumbing things down. Read his complete article instead: http://onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionInRuby.rdoc
Eelco
Exactly, that's why I linked to the full article in my first sentence.
Ryan McGeary
+1  A: 

Dhanji R. Prasanna's book Dependency Injection In Action is great.

I used to think - having written DI frameworks years ago before the term even got coined - that DI was all hype. However, since I recently had to work with a code base completely based on singletons and factories, I now see the problems with not using DI for at least portions of your code. That DI-less code was incredibly tightly coupled, which had the unfortunate effect that simple changes result in an avalanche of cascading effects.

Reading Dependency In Action was an eye opener in the sense that it articulated what I instinctively knew, but what never quite crystalized in my mind. Also, there are interesting tips throughout the book about some of the common pitfalls when implementing DI, and even a chapter with tips for framework developers!

I think more people can learn from this book than they realize. In my experience, a lot of people use frameworks like Spring because everyone else uses it, without really understanding the core problem it solves. This book will give you that background.

Eelco
+1  A: 

Despite recent posts that might confuse the matter, Agile Principles, Patterns and Techniques in C# and the Java equivalent from Robert C Martin (and Micah Martin for the former) covers the space very well too - in terms of concepts more than trying to provide a 200 page manual for a specific version of a specific DI container (or a laundry list of the state of the art in a space that's still evolving).

Ruben Bartelink
+4  A: 

Dependency Injection in .NET is my favorite book on this subject, and it changed my way of thinking, as in my previous projects I was doing almost every mistake illustrated in chapter 5: DI Anti-Patterns

alexandrul
+1 I'm looking forward to this - Mark expends an inordinate amount of time around here expanding his and our knowledge of DI approaches, nuances, patterns and anti-patterns. (Though Spolksy's Spanner In The Works has probably poisoned the waters for >200 page books on DI!)
Ruben Bartelink
A: 

Pro ASP.NET MVC Framework by Steve Sanderson has great info on IoC and dependency injection. I got this book to learn MVC, but it did a great job of teaching me IoC as well.

IoC is used extensively throughout the examples. It also has good coverage of TDD and Moq.

The IoC container used in this book is Castle Windsor.

frankadelic