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.
87
82%
Does it follow best practices?
Impact
100%
1.01xAverage score across 3 eval scenarios
Passed
No known issues
Refactor global-state Go service to constructor injection
No global service vars
100%
100%
No init() for setup
100%
100%
Constructor injection
100%
100%
Interface at consumer
70%
100%
Infrastructure first in main
100%
100%
No cross-service globals
100%
100%
DB not hidden inside service
100%
100%
Concrete struct returned
100%
100%
Refactoring notes present
100%
100%
Notes mention testability
100%
100%
google/wire provider sets and injector setup
wireinject build constraint
100%
100%
wire.Build call
100%
100%
wire.NewSet grouping
100%
100%
wire.Bind for interfaces
100%
100%
Injector returns App
100%
100%
No manual wire_gen edit
100%
100%
Build constraint explained
100%
100%
wire_gen.go commit guidance
100%
100%
No lifecycle management claimed
100%
100%
Providers return concrete types
100%
100%
uber-go/fx lifecycle hooks and domain module organization
fx.Lifecycle OnStart hook
100%
100%
fx.Lifecycle OnStop hook
100%
100%
Lifecycle hook context param
100%
100%
fx.Module for infra
100%
100%
fx.Module for domains
100%
100%
Modules composed in main
100%
100%
No container as dependency
100%
100%
fx.Invoke for startup
100%
100%
Lifecycle hooks explained
100%
100%
Container not passed explained
100%
100%
8c7e016
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.