What are the Types of Ioc?

Asked

Viewed 481 times

14

Reading the Book "Pro Spring Security" by Carlo Scarioni of Editora Apress, 2013 edition, 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 needed dependencies, the dependencies are Somehow Given to the Object. In a polymorphic way, the Objects that are Given as dependencies to the target Object that depends on them are known to this target Object just by an abstraction (like an interface in Java) and not by the Exact implementation of the dependency.

Meaning DI is a kind of Inversion of Control (Ioc), but no other project pattern that characterizes as Ioc, while researching found this article (Inversion of Control Containers and the Dependency Injection Pattern - Dependency Injection) of Martin Fowler who 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 (Styles), not types, and they’re all Dependency Injection, then what are the other types of Ioc? or would be an error of the edition in question/author of the cited book?

  • 5
  • 1

    In this same Fowler article you referenced it explains an alternative to dependency injection in the implementation of inversion control: the Service Locator. Do not exist "guys" ioc, but yes Patterns design to implement it. In addition to the dependency injection and the Locator service, I have also seen the simple use of configuration files, which determines which service should be used when the code where the control is reversed needs that particular type of service.

  • 2

    Other forms of Ioc implementation I’ve seen: event orientation, Observer, plug-ins or add-ins, Convention over Configuration (where the code where the control was reversed knows which service to instantiate and use based on a default of names for the service), annotations (Java) or Attributes (C#)... I must have seen more but it doesn’t occur to me now.

  • 2

    @Caffé, it would be more appropriate to post your comment as a response.

2 answers

3


There are four ways to implement Dependency Injection:

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

Source: http://www.devmedia.com.br/design-patterns-injecao-de-dependencia-com-c/23671

1

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

  • Standard Factory
  • Standard Service Locator
  • Dependency injection

Browser other questions tagged

You are not signed in. Login or sign up in order to post.