What is IoC (Inversion of Control)? - SoftwareDesign/MEFResearch GitHub Wiki
The pseudocode snippet shows the conventional console application:
static int main(string arg[])
{
string data = ClassFromLibrary.GetSomeData();
string processResult = ProcessData(data);
ShowResult(processResult);
}
From this code snippet we can see we call the methods from a Libary (a set of classes or methods, Framework is also a set of class but Framework all controls application running) to process some data, but we are controlling the main flow of the application not the library.
If we implement similar business logic in a UI application, the data may input by user. And we will write some event handler which handles the data processing. But the event handler we writes is not called by us, it's called by the UI Framework (Or UI message loop), and we can't determine when to call it. So clearly here is the UI Framework is controlling the application not us. This means the control of the application inverted. This is the concept of Inversion of Control (IoC).
IoC is not a technology it's a generic concept (term). IoC is not Ioc Container. The reason why we call IoC container is because the container uses IoC concept. Some people says IoC and Dependency Injection are two concepts, it's not very precise. Actually Dependency Injection is the pattern that most of the IoC contains use to implement IoC concept. Then what the IoC container is inverting? The answer is the inversion of how they lookup a dependency implementation.
If we wrap it up we can say IoC is "Hollywood Principle" which is "Don't all us, we'll call you".
Martin Flower clearly explained what is IoC? Link below is the IoC article written by Martin Flower http://martinfowler.com/bliki/InversionOfControl.html
There is another pattern which can be used to implement IoC concept called "Service Locator".
Here is another link which explain the relationship between "IoC", "Dependency Injection" and "Service Locator". http://martinfowler.com/articles/injection.html
These article is written by Martin Fowler, he owns the copyrights of these articles.