talira

Google's lightweight dependency injection framework for Java

open sourceApache-2.0free

Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 11 and later from Google, which has used it in mission-critical applications since 2006. It removes most of the need for factories and new in your code (its makers call @Inject the new new), embraces Java's type safety, keeps its feature set small, and avoids surprises and magic so code stays understandable. Version 6.0.0 supports javax.inject, servlet and persistence, and 7.0.0 the jakarta equivalents; they're otherwise the same. It's Apache 2.0 licensed, with a user guide in its wiki and Javadocs per release.

Problems it solves

  • I want dependency injection in my Java app without a full framework like Spring
  • I need to stop wiring objects together with factories in Java
  • I want type-safe dependency injection for a Java library

Features

  • Dependency injection with @Inject
  • Type-safe bindings in Java code
  • Small, deliberately limited feature set
  • javax (6.0.0) and jakarta (7.0.0) releases
  • User guide and Javadocs

Alternatives

The same job

These do what Guice does.

  1. Dagger A fast dependency injector for Android and Java
  2. Weld The reference implementation of Jakarta CDI
  3. Koin Pragmatic dependency injection for Kotlin and Kotlin Multiplatform

Compare Guice with the top 3