Inversion of Control & Dependency Injection

What is IOC Principle: Inversion of control (IoC) is a design principle in which custom-written portions of a computer program receive the flow of control from a generic framework.

In simple words, IOC is inverting the control from called class to calling class.

DI: Dependency Injection is a design principle in which code creating a new object supplies the other objects that the new object depends upon for operation. This is a special case of inversion of control. Often a dependency injection framework (or “container”) is used to manage and automate the construction and lifetimes of interdependent objects.

DI is ability to supply(inject) external dependencies into a class at run time. Continue reading “Inversion of Control & Dependency Injection”