Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency Injection in Java

 
Shiv Swaminathan
Ranch Hand
Posts: 48
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the Table of Contents for "The Well Grounded Java Developer".

Chapter 3 is on Dependency Injection.

Some basic questions:

1. Is the DI in Java similar to what Spring framework offers? Is it a remake?
2. Does Java just provide the Spec for DI and we need some vendor implementation for this spec to utilize DI?
3. How can I make my current Java code to utilize Java DI?
4. Do I necessarily need to use Guice API's to achieve Java DI?
5. Do we have any other implementation available for Java DI other than Guice?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) It is a standard inspired by Spring (and more)
2) I believe you need some sort of DI container.
3) Look for things you'd like to decouple. For example, when writing test code, it is common to inject an implementation of an interface.
4) No
5) Spring and PicoContainer.
 
Shiv Swaminathan
Ranch Hand
Posts: 48
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring framework on DI was there before Java came up with any DI specs.
How can it be that Spring is implementing java DI?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very common pattern is software. Good ideas become design patterns, design patterns are bult into frameworks (like Spring) and then into a language itself (the JSR-330 std for Java). Spring 3.x simply implements the common JSR-330 std + some extras.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shiv,
That's how JPA came about too.

1) Hibernate started.
2) JPA spec came out
3) Hibernate provided set of APIs to be compliant with JPA spec
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic