Geeks With Blogs
Lee Brandt's Blog You're only as smart as your last line of code

I've spent the last week reading about Dependency Injection, and I think I may finally understand. First of all it is a type of Inverion of Control. Now .NET programmers see inversion of control all the time. Usually in the same place we encounter delegates: event handlers. The event handler actually controls the handling of the event and not the main program.

But Dependency Injection is a step beyond. DI inverts control of the program so that a dependent object is injected into its dependant object. So if I have an object [Foo] that depends on a [IBar] type, I can make a call to a container class (aptly named a Dependency Injection Container) and have it inject into the [Foo] object a concrete instance of a class that implements [IBar]. This relieves the actual dependency on the concrete instance of a class that implements [IBar]. To me, it's a bit like the Factory Pattern on steroids. I also read a bit about Service Locator, but that's about all my little brain can handle for now.



Posted on Thursday, April 3, 2008 1:13 PM Dependency Injection | Back to top

Comments on this post: Dependency Injection Containers

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Lee Brandt | Powered by: