What problem does it solve?
Dependency injection in Go is often mishandled, leading to hard-to-test code, tight coupling, and hidden dependencies. This Skill provides a practical, decision-driven approach to structuring DI in Go projects, including constructor-based injection, library choices, interface design at consumption sites, and lifecycle considerations to keep code maintainable.
Core Features & Use Cases
- Clear guidelines for when to use manual constructor injection vs. DI libraries (google/wire, uber-go/dig, uber-go/fx, samber/do)
- Best practices: define interfaces at the consumer boundary, avoid global registries, keep the container at the composition root, and favor lazy initialization
- Real-world scenarios: refactoring tightly coupled code, designing service architectures, implementing singletons vs. transients, and performing DI in small to large Go services
Quick Start
Create a simple wiring example in main.go that demonstrates manual constructor injection from configuration to infrastructure to repositories to services to transport.