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.
82
86%
Does it follow best practices?
Impact
100%
1.00xAverage score across 2 eval scenarios
Passed
No findings from the security scan
DI migration plan for tightly coupled Go codebase
Global DB var identified
100%
100%
init() DB setup identified
100%
100%
Global mailer var identified
100%
100%
Constructor injection proposed for globals
100%
100%
Concrete store dependency identified
100%
100%
Concrete mailer dependency identified
100%
100%
Interface defined at consumer
100%
100%
Service-locator identified
100%
100%
Service-locator replacement proposed
100%
100%
DI library recommendation present
100%
100%
Small project → manual or lightweight library
100%
100%
refactoring-steps.md produced
100%
100%
Three sections present
100%
100%
uber-go/fx domain modules and lifecycle hooks
These are not visible to scoring or included in the download.
/home/agent/go/pkg/mod/cache/download/github.com/davecgh/go-spew/@v/list
/home/agent/go/pkg/mod/cache/download/github.com/davecgh/go-spew/@v/v1.1.1.lock
/home/agent/go/pkg/mod/cache/download/github.com/davecgh/go-spew/@v/v1.1.1.mod
/home/agent/go/pkg/mod/cache/download/github.com/davecgh/go-spew/@v/v1.1.1.zip
/home/agent/go/pkg/mod/cache/download/github.com/davecgh/go-spew/@v/v1.1.1.ziphash
These are not visible to scoring or included in the download.
/home/agent/go/pkg/mod/cache/download/github.com/cespare/xxhash/v2/@v/list
/home/agent/go/pkg/mod/cache/download/github.com/cespare/xxhash/v2/@v/v2.1.2.info
/home/agent/go/pkg/mod/cache/download/github.com/cespare/xxhash/v2/@v/v2.1.2.lock
/home/agent/go/pkg/mod/cache/download/github.com/cespare/xxhash/v2/@v/v2.1.2.mod
/home/agent/go/pkg/mod/cache/download/github.com/cespare/xxhash/v2/@v/v2.1.2.zip
Infra module grouping
100%
100%
User domain module
100%
100%
Order domain module
100%
100%
Multiple modules used
100%
100%
No flat wiring
100%
100%
Lifecycle parameter
100%
100%
Hook registration
100%
100%
OnStart hook
100%
100%
OnStop hook
100%
100%
Stateful resource lifecycle
100%
100%
19a0626
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.