22

I'm getting the feeling that there's is not such thing as inversion of control or rather the correct term is dependency injection. Am I wrong to assume this?

I've been trying to define IoC for my own sake. In doing so I've learned a great deal about IoC containers and dependency injection.

Just now, I read this from Martin Fowler's website:

As a result I think we need a more specific name for this pattern. Inversion of Control is too generic a term, and thus people find it confusing. As a result with a lot of discussion with various IoC advocates we settled on the name Dependency Injection.

In the world of modern IoC isn't dependency injection just one way to achieve IoC?

1

3 Answers 3

44

If you accept Fowler's definition, Inversion of Control is a much broader term than DI that covers all framework usage where you plug into a framework, but the framework is still in control.

For example, in .NET, frameworks such as ASP.NET or Windows Presentation Foundation are ultimately in control, but provide various events and Seams you can use to build an application. The same is true on other platforms.

Dependency Injection is a specialization of IoC that applies IoC specifically to manage dependencies.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, that does clarify things. Do you know of a place where I might find more examples of IoC?
In reality, IoC (as opposed to DI) is everywhere in OO. It's harder to find examples of the opposite. I'm only really knowledgeable of the .NET platform, but almost any type of sub-framework you use there (ASP.NET, Windows Forms, WCF etc.) are IoC frameworks. Only console apps really fall outside of this category.
That's an assurance given Fowler's statement: "Inversion of Control is too generic a term". To be more specific, I'd love to see DP and IoC examples. I'm really hung up on learning more about how to achive good IoC through DP.
@Mark - Yes, silly typo. I'm learning about how to leverage IoC and DI and code examples would definitely go along way there.
Well, I am working on a book on the subject if you can read C# examples... manning.com/seemann
6

That's one of the few points me and Mark disagree on. By my book, Inversion of Control principle is same as here so I won't rehash it.

Dependency injection is merely an act of externalizing creation of dependencies to the outside world by components.

Managing these dependencies (and lots of other stuff) is what Inversion of Control Containers do, and using DI as part of it, is merely an implementation detail.

Comments

4

Yes, IoC means the class itself does not control things, but is called from outside. Dependency injection is the way to do this.

Dependency injection is indeed a much more concrete term, more well-defined than inversion of control.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.