Comprehensive guide for dependency injection (DI) in Golang. Covers why DI matters (testability, loose coupling, separation of concerns, lifecycle management), manual constructor injection, and DI library comparison (google/wire, uber-go/dig, uber-go/fx, samber/do). Use this skill when designing service architecture, setting up dependency injection, refactoring tightly coupled code, managing singletons or service factories, or when the user asks about inversion of control, service containers, or wiring dependencies in Go. For a specific DI library, → See `samber/cc-skills-golang@golang-google-wire`, `samber/cc-skills-golang@golang-uber-dig`, `samber/cc-skills-golang@golang-uber-fx`, or `samber/cc-skills-golang@golang-samber-do` skills.
80
86%
Does it follow best practices?
Impact
83%
1.00xAverage score across 2 eval scenarios
Passed
No findings from the security scan
samber/do container override testing pattern
do.OverrideValue usage
0%
0%
Injector-resolved service under test
100%
100%
Real service left un-overridden
0%
0%
Interface-boundary mocking
100%
100%
Interface defined at consumer
100%
100%
No global variables for services
100%
100%
Constructor injection
100%
100%
samber/do v2 import
100%
100%
Test verifies email recipient
100%
100%
No service locator pattern
100%
100%
Manual DI initialization order in Go CLI
Config initialized first
100%
100%
Store before fetcher
100%
100%
Fetcher before handler
100%
100%
No DI library import
100%
100%
Constructor injection
100%
100%
No global service variables
100%
100%
No init() service setup
100%
100%
Interface at consumer
70%
70%
Composition root in main
100%
100%
Dependencies passed down
100%
100%
4158351
Table of Contents
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.