What problem does it solve?
Dependency injection (DI) removes hidden dependencies by forcing Go services to receive their collaborators explicitly, making code easier to test, refactor, and maintain.
Core Features & Use Cases
- Constructor-based wiring: Use explicit constructor injection to prevent global variables and init-driven service setup.
- Interface-first boundaries: Define interfaces at the point of consumption to decouple services from concrete implementations.
- Correct composition root: Keep any DI container limited to application startup, avoiding the service-locator anti-pattern (passing containers into services).
- Practical library selection: Compare manual DI, google/wire (codegen), uber-go/dig+fx (reflection framework), and samber/do (generics-based, with lifecycle support).
- Refactoring guidance: Provide a structured approach to untangle coupled code paths by identifying global init patterns, dependency surfaces, and service-locator misuse.
- Testing with mocks: Inject mock implementations at interface boundaries to test business logic without real infrastructure.
Quick Start
Ask the AI to refactor your Go service to use constructor injection, then choose between manual DI, google/wire, dig+fx, or samber/do based on your service count and lifecycle needs.