VOOZH about

URL: https://www.javacodegeeks.com/2014/02/dependency-injection-options-for-java.html

⇱ Dependency Injection Options for Java


I wanted to take some time to put together a summary of some popular dependency injection (DI) frameworks for Java. This is a high-level overview of what’s available.

First off, what is dependency injection?

“Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it possible to change them, whether at run-time or compile-time.” – Wikipedia

If you’ve ever had a constructor with 12 parameters, you’ve already encountered a compelling reason to use dependency injection.

Most objects require references to other objects to be useful. Dependency injection allows the system to provide those references without you having to manage all of those dependencies at the application level.

This sounds complicated, but it’s really not. Since this is not an in-depth discussion of dependency injection, check out the Wikipedia page for several examples in various languages.

Square Dagger

Beginning with one of the simplest, most lightweight frameworks available, Square Dagger is a tiny library (<100KB) that is useful for programs that must minimize their footprint, as in the case of mobile applications. It lacks many of the features of the larger frameworks, but it makes it up in speed and a neat compile-time validation tool.

Google Guice

Guice is Google’s attempt to create a feature-rich, independent DI facility. It is useful in most applications, especially web development. It provides a lot more features than Dagger, but it is slower and can be complex.

👁 Photo of Keyhole Software
Keyhole Software
February 25th, 2014Last Updated: February 25th, 2014
6 283 1 minute read

Keyhole Software

Keyhole is a midwest-based consulting firm with a tight-knit technical team. We work primarily with Java, JavaScript and .NET technologies, specializing in application development. We love the challenge that comes in consulting and blog often regarding some of the technical situations and technologies we face.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

6 Comments
Oldest
Newest Most Voted
Michael Russo
12 years ago

Looks like you missed the header for Spring DI, making it look like Guice flows right into Spring.

2
Reply
KB
12 years ago

“Square Dagger” is really just called “Dagger.”

(For that matter, “Google Guice” is just “Guice”, but in that case at least it really was primarily driven by just the one company.)

0
Reply
11 years ago

Can I suggest a new DIC project? http://fbn.github.io/gimple/
It’s a Micro (one class) DIC container inspired by PHP PImple.

0
Reply
7 years ago

Very old article, but also note that now you can use CDI in Java SE as well, not only Java EE

0
Reply
6 years ago

Good beginner information also provide updated info on data binding’s waiting for it

0
Reply
6 years ago

a simple way to learn dagger 2

0
Reply
Back to top button
Close
wpDiscuz