What are the Types of IoC?

12

Reading the "Pro Spring Security " book by Carlo Scarioni from Apress Publishing, issue 2013, I came across the following text that left me confused about IoC:

  The basic idea of DI, a type of Inversion of Control (IoC) , is simply that instead of having an object instantiate its dependencies, the dependencies are somehow given to the object. In a polymorphic way, the objects that are given dependencies to the target object that depends on them are known to this target object by an abstraction (like an interface in Java) and not by the exact implementation of the dependency. >

In other words, DI is a type of Inversion of Control (IoC), but no other design pattern that is characterized as IoC, when searching I found this article (Inversion of Control Containers and the Dependency Injection Pattern - Dependency Injection by Martin Fowler that explains, but leads to another understanding (which I think is correct):

  

There are three main styles of dependency injection. The names I'm using for them are Constructor Injection , Setter Injection , and Interface Injection . ...

Well Martin Fowler says there are three styles, not types, and they are all Dependency Injection , so what are the other types of IoC? or would it be an error in the issue in question / author of the book quoted?

    
asked by anonymous 07.07.2015 / 02:57

2 answers

3

There are four ways to implement Dependency Injection:

  • Constructor: How we implement dependency injection in defining class constructors;
  • Getter and Setter: How we implement dependency injection in the definition of class Gets and Sets;
  • Interface Implementation: The way in which the definition of Interfaces is used to perform dependency injection;
  • Service Locator: How we construct classes that serve as "locators" of objects that we will instantiate in our other classes.

Source: link

    
28.07.2015 / 14:43
1

The types you refer to are the 3 ways to implement control inversion, which are:

  • Factory Default
  • Default Service Locator
  • Dependency injection
27.07.2015 / 22:11