What problem does it solve?
It eliminates brittle, manual construction of complex Go object graphs by letting you declaratively wire dependencies and have dig resolve them safely at composition time.
Core Features & Use Cases
- Lazy, memoized construction: Use constructors with
Provide so each dependency is built once per container and reused where needed.
- Clean parameter/result wiring: Use
dig.In/dig.Out to manage many dependencies, including named values, value groups, and optional dependencies.
- Disambiguation and interface exposure: Use
dig.Name to select between multiple values of the same type and dig.As to expose concrete implementations only through interfaces.
- Graph validation and error clarity: Validate wiring early with
DryRun(true) and get dependency-path error messages when Invoke fails.
- Scope-local composition: Create child scopes for request/tenant/module boundaries so per-request values don’t leak across concurrent executions.
- Testing-friendly DI: Build fresh containers per test, override providers via decoration, and validate graphs without running side-effecting constructors.
Quick Start
Use the golang-uber-dig skill to wire an HTTP service where many route constructors automatically contribute handlers into a routes group consumed by a single server constructor, ensuring missing providers fail at startup.