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.
87
82%
Does it follow best practices?
Impact
99%
1.05xAverage score across 3 eval scenarios
Passed
No known issues
samber/do generics API and lifecycle shutdown
do.New() injector
100%
100%
do.Provide() registration
100%
100%
Generic MustInvoke syntax
70%
100%
Internal dependency resolution
100%
100%
Injector not passed to services
100%
100%
Stateful singletons
100%
100%
Graceful shutdown
100%
100%
Correct import path
0%
100%
Constructor injection in services
50%
80%
No global variables
100%
100%
No reflection-based alternative
100%
100%
Manual DI layered initialization order
Infrastructure initialized first
100%
100%
Repositories after infrastructure
100%
100%
Services after repositories
100%
100%
Transport initialized last
100%
100%
No DI library used
100%
100%
Constructor injection
100%
100%
No global service variables
100%
100%
Wiring centralized in main
100%
100%
Interfaces accepted at boundaries
100%
100%
Config initialized before infrastructure
100%
100%
Graceful shutdown wired
100%
100%
fx module domain organization and lifecycle
fx.Module for domain grouping
100%
100%
Separate infra module
100%
100%
Separate service/domain module
100%
100%
fx.Lifecycle in provider
100%
100%
OnStart hook registered
100%
100%
OnStop hook registered
100%
100%
Context parameter in hooks
100%
100%
Modules composed in fx.New
100%
100%
No per-request container
100%
100%
app.Run() for lifecycle
100%
100%
No global service variables
100%
100%
e9761db
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.