I don't think you're going to get an authoritative answer on this one because the term "IoC" is kind of overloaded and to say "the one true meaning of IoC is..." is kind of pedantic. But I'll share my opinion anyway :)
Dependency Inversion is about depending on an abstraction. Consider a HelloWorld
class that depends on an IStringWriter
, and an implementation class ConsoleStringWriter
.
Inversion of Control is when the framework/infrastructure invokes application code, rather than the other way around. For example, when a user closes a WPF app, you don't call the framework, it raises an event that you can subscribe to.
They are often combined. For example, Hibernate depends on the abstraction defined by its Interceptor interface in order to implement IoC. From an Interceptor's point of view, control is inverted - Hibernate calls the Interceptor. Another example you see all over is IHandle<T>
where T is an Event or a Command or a Message - the infrastructure calls the handler at the right time.
Its confusing because we call them "IoC containers", but you can do DI without doing IoC. If you inject a ConsoleStringWriter
into a HelloWorld
I don't really think of this as IoC because there is no "framework" or "infrastructure". But that's because Hello World is trivial - as an application becomes more complex the need for IoC increases.
See also this question and accepted answer.