Dependency Injection is not a bad word

by MikeHogg 12. December 2012 10:10

"Dependency Injection" is not a bad word.  Besides the fact that it's two words, if anything is bad abou it, it is only that "Dependency" is a bad word,  not Injection.  If you can't encapsulate everything necessary for your class or system to work, then what you want to do is expose your dependencies, in a contract, so other developers can easily figure out what is needed to get what they want from your library.

 

You can do this by limiting constructor signatures, or method signatures, to individual properties that you rely on, or by providing a signature that takes an entire class, and that is what they usually call dependency injection.

 

Let's say you have a custom MembershipProvider, and it provides several public methods, which other developers might find browsing your namespace.  Let's say another developer finds what she is looking for in your dll, and so tries to use it in his case. Let's say you aren't exposing any static methods, so they must now instantiate this object, and any dependencies your classes have become an issue.

Tags:

Architecture

Add comment

biuquote
  • Comment
  • Preview
Loading

About Mike Hogg

Mike Hogg is a c# developer in Brooklyn.

More Here

Favorite Books

This book had the most influence on my coding style. It drastically changed the way I write code and turned me on to test driven development even if I don't always use it. It made me write clearer, functional-style code using more principles such as DRY, encapsulation, single responsibility, and more. amazon.com

This book opened my eyes to a methodical and systematic approach to upgrading legacy codebases step by step. Incrementally transforming code blocks into testable code before making improvements. amazon.com

More Here