Guice wires object graphs in Java 11+ apps with type-safe binding instead of hand-written factories. Teams annotate fields and constructors with inject markers to receive implementations.
Overview
Guice is a dependency injection framework for Java maintained by Google. It reduces boilerplate around constructing objects and choosing concrete implementations for interfaces, positioning injection as a replacement for widespread use of the new operator and custom factory classes in application code.
The design favors Java’s type system: bindings are declared in modules and resolved at runtime with clear error messages when wiring fails. The API stays small relative to a full enterprise stack; extensions cover servlets, persistence, and related integrations via separate artifacts installable from Maven Central.
Guice emphasizes predictable behavior over hidden magic so code remains readable with or without IDE assistance. The project documents a user guide and compares injection to factories for newcomers.
Applications add Guice Core (and optional extensions) through Maven or other build tools listed on Maven Central. Release lines differ mainly in javax versus jakarta inject and related APIs, so teams pick the variant that matches their servlet and persistence stack.
Key features
- Constructor and field injection
- Type-safe binding modules
- Reduced factory boilerplate
- Servlet and persistence extensions
- Maven Central distribution
- javax and jakarta variants
Use cases
- Wiring large Java service layers
- Testable object graph configuration
- Replacing hand-rolled factories
- Modular binding per deployment