IoC Container && Depency Injection


The Inversion of Control,(IoC) pattern is all about removing dependencies from your code, means, management of create instance with application framework.
So how is the process of injecting dependencies? Hence some people says IoC Container and some people says Depency Injection(DI) container but both terms indicate to the same thing.

What is Depency Injection?
Dependency Injection, which is the last of the SOLID policies, as I mentioned above, the level difference classes (high-low) injects its dependencies from the outside.

Let’s try to explain with an example;

public class ProductManager
private ProductDao _productDao;

public ProductManager() {
_productDao= new ProductDao();

public class ProductManager
private readonly IProductDao _productDao;

public ProductManager (IProductDao productDao)
_productDao = productDao;

In the above example, Even if our ProductDao class is changed, the ProductManager will not be affected.
This made our code more flexible, manageable and easier to maintain.

What are the commonly used IOC Containers?
Autofac, Ninject, Unity and CastleWindor are popular containers. You can select according to need your project.

1. Your code is free.
2. Use Interface concepts.
3. Unit test becomes writable.

1. Getting used to getting started is difficult
2. Life Time Management is complicated to check and a situation that needs attention.