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.
89
86%
Does it follow best practices?
Impact
100%
1.00xAverage score across 3 eval scenarios
Passed
No known issues
Refactor globals to constructor injection
No package-level DB var
100%
100%
No package-level logger var
100%
100%
No init() for service setup
100%
100%
Constructor injection
100%
100%
Wiring in main()
100%
100%
Infrastructure-first order
100%
100%
Interface at consumer
100%
100%
No global registry
100%
100%
Struct holds dependencies
100%
100%
Refactor notes present
100%
100%
samber/do testing with clone override
Uses samber/do
100%
100%
Container not in service
100%
100%
Override/clone for mocking
100%
100%
Mock at interface boundary
100%
100%
No real transport in tests
100%
100%
Production wiring in main
100%
100%
Singleton for stateful deps
100%
100%
Tests cover email path
100%
100%
Tests cover push path
100%
100%
No code generation
100%
100%
fx lifecycle hooks and module grouping
fx.Lifecycle for DB
100%
100%
OnStart hook present
100%
100%
OnStop hook present
100%
100%
fx.Module grouping
100%
100%
fx.New in main
100%
100%
app.Run() usage
100%
100%
No container as dependency
100%
100%
Lifecycle ctx parameter
100%
100%
Infrastructure module
100%
100%
No global service vars
100%
100%
Wiring notes present
100%
100%
b88f91d
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.