• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

what is the difference between DI and Spring IOC? or both is same?

Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Is there any difference between IOC and DI or both are same?

Posts: 1051
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are not the same but they tend to be described together, hence the confusion.

Inversion of Control (IoC) means that objects do not construct other objects on which they rely on. Instead, the application will get these objects from an external framework (an IoC container). One method which provides these objects to the application is called Dependency Injection (DI).
Posts: 2759
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IoC really means that code that doesn't have business logic drives code that contains business logic. A simple example is Servlet:- Technically, the way web container loads and uses servlets is IoC (even though the concepts of Servlets predates popular use of the term) The web container that contains logic for serving HTTP requests is calling the servlet. If you would do this in a non IoC way then you would have a HTTP Parser class and some sort of socket communication class that your servlet will call to listen for HTTP requests. Doing it the non-IoC also means that the generic code is not a container so it can't provide functionality like thread management, etc. Technically, you can have IoC without DI. The servlet container doesn't have DI.. but it does IoC

Technically, you can have DI without IoC, too. DI basically means that there is a module that is responsible for initializing all objects in the system. ALso, when objects are dependent on other objects, the DI module will give reference of objects to objects:- basically this process is called injection of dependencies. If A depends on B, the DI module will initialize A, initialize B, and give the reference of B to A:- the DI module has injected B into A. Now, technically, you could implement your own module that has intimate knowledge of the structure of your program. You can call the DI module from your init/main method and all of your objects will be created. Techncially, this is still DI, just not a very good one, because all the rules for constructing the objects is "hardcoded"

IoC and DI just maike sense together. IoC needs some sort of factory pattern, and using DI solves a lot of problems.
Paper beats rock. Scissors beats tiny ad.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic