2

guys

As i know ,Dependency injection is a implementation of Ioc

But I am not clear about the relationship between dependency lookup & Ioc

,Is dependency lookup also a implementation of Ioc.

Can anyone help this? thanks!

jason zhong
  • 101
  • 1
  • 9
  • Nope. Dependency Injection is not an implementation of IoC. Inversion of Control is a [defining characteristic of a framework](http://martinfowler.com/bliki/InversionOfControl.html) and allows a framework to run user code. DI however can be used both with or without a framework. Dependency Injection is also often seen as a specific form of the Dependency Inversion Principle, but even this is incorrect, since it is easy to apply dependency injection while violating the Dependency Inversion Principle. But they are of course all related. – Steven Oct 08 '14 at 10:14
  • from matin fowler's article,dependency injection is just another name of Ioc ,he defined dependency injection in this article,Am i right?[Inversion of Control Containers and the Dependency Injection pattern](http://martinfowler.com/articles/injection.html) – jason zhong Oct 09 '14 at 07:22
  • From [this article from Martin Fowler](http://martinfowler.com/bliki/InversionOfControl.html) "Inversion of Control is [...] seen as a defining characteristic of a framework." – Steven Oct 09 '14 at 08:36

1 Answers1

4

I'm no spring expert, but my £0.02.

Dependency injection is externalisation of provision of dependecies.

Dependency lookup is centralisation of provision of dependencies.

with DI the dependencies something has are provided to the object by something else, ideally when the object is constructed. This may or may not involve a framework.

Dependency lookup is when the object itself tries to create the dependencies it needs using some generic service. In spring I believe this is effectively asking Spring for the type of object it needs and the container resolving the object type there and then (ref).

This is effectively the ServiceLocator (anti-) pattern (more details). Although not everyone is convinced its an anti pattern

IMHO you should strive to use DI in all cases and should not use dependency lookup at all.

Community
  • 1
  • 1
Sam Holder
  • 32,535
  • 13
  • 101
  • 181