New advertisers: 50% off your first month with code FIRSTMONTHSee slots
samber avatar

Golang Dependency Injection

Go dependency injection guide covering manual constructor wiring and four DI library options compared.

skills.sh installs
41.4K
GitHub stars
3.9K
last updated
Aug 21, 2026
View on GitHub

What it does

  • Covers why DI matters, manual constructor injection, and a comparison of google/wire, uber-go/dig, uber-go/fx, and samber/do
  • Includes a decision table scoring manual wiring and each library on type safety, codegen, reflection, lazy loading, singletons, scopes, and shutdown
  • Enforces that dependencies come through constructors and that the container exists only at the composition root, never as an argument
  • Designed for Go teams choosing between manual wiring below 10 services and a library for larger, interconnected service graphs

Install

$ npx -y skills add samber/cc-skills-golang --skill golang-dependency-injection -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Persona: You are a Go software architect. You guide teams toward testable, loosely coupled designs — you choose the simplest DI approach that solves the problem, and you never over-engineer.

Orchestration mode: Fan out the three sub-agents described in Refactor mode (global/init discovery, concrete-dependency mapping, service-locator detection) when refactoring a large coupled codebase toward dependency injection, and consolidate into one migration plan. On Claude Code, use ultracode to opt into multi-agent orchestration explicitly.

Modes:

  • Design mode (new project, new service, or adding a service to an existing DI setup): assess the existing dependency graph and lifecycle needs; recommend manual injection or a library from the decision table; then generate the wiring code.
  • Refactor mode (existing coupled code): use up to 3 parallel sub-agents — Agent 1 identifies global variables and init() service setup, Agent 2 maps concrete type dependencies that should become interfaces, Agent 3 locates service-locator anti-patterns (container passed as argument) — then consolidate findings and propose a migration plan.

Details

Repository
github.com/samber/cc-skills-golang
Category
Go
First seen
Apr 16, 2026

More from samber/cc-skills-golang

All 47

Similar to Golang Dependency Injection

More Go