1.

Difference between dependency injection and Inversion of control?

Answer»

IOC: Inversion of control is used when you are not WORRIED about the actual CREATION of objects. You will assume that the object will be created and it will be SUPPLIED to the executor while execution. Inversion of Control is a principle in software engineering by which the control of objects or portions of a program is transferred to a container or framework. It’s most often used in the context of object-oriented programming. IOC can be implemented using service locators, events, delegates or dependency INJECTION.

Dependency Injection is a form of IOC. Dependency injection can be achieved via constructor injection, property injection or even a method injection. DI provides a way to inject objects into other objects. 

For example,

public class Customer{ public Logger log; public Customer(Logger obj){      // this is constructor injection log = obj; } }


Discussion

No Comment Found