samber avatar

Golang Dependency Injection

If you're building Go services with more than a handful of dependencies, this walks you through the entire DI spectrum: when manual constructor injection is enough, when to reach for a library, and how to pick between Wire's codegen, Fx's reflection magic, or samber/do's generics approach. The decision table alone is worth it. What I like: it doesn't just show you library syntax, it teaches you to spot global variable anti-patterns and service locator smells, then gives you a three agent refactoring strategy to fix them. Treats DI as an architecture question, not just a framework choice. Written by the author of samber/do but stays honest about the tradeoffs.

skills.sh installs
41K
GitHub stars
3.8K
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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.

Sponsors

Details

Repository
github.com/samber/cc-skills-golang
Categories
Documentation, Code Review & Quality, Go
First seen
Apr 16, 2026

More from samber/cc-skills-golang

All 47
1pexoai avatarpexo-agentpexoai/pexo-skillsAI video generation skill with auto model selection across Seedance 2, Kling 3.0, HappyHorse, and 10+ models. Produces finished multi-shot videos (5–120s) from 40.6Kskills.sh installs
2wshobson avatarpython-testing-patternswshobson/agentsImplement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, o40Kskills.sh installs
3heygen-com avatarstyle-samplingheygen-com/hyperframesMake a new episode in a proven video style - Collage Explainer, Finance Explainer, Animated Science Explainer, 3D Brand Explainer, 3D True Crime - on the person38.8Kskills.sh installs
4samber avatargolang-spf13-cobrasamber/cc-skills-golangGolang CLI command tree library using spf13/cobra — cobra.Command, RunE vs Run, PersistentPreRunE hook chain, Args validators (NoArgs, ExactArgs, MatchAll, cust38.6Kskills.sh installs
5samber avatargolang-graphqlsamber/cc-skills-golangImplements GraphQL APIs in Golang using gqlgen or graphql-go. Apply when building GraphQL servers, designing schemas, writing resolvers, handling subscriptions,38.5Kskills.sh installs
6samber avatargolang-how-tosamber/cc-skills-golangGolang skills orchestrator — always active on any Golang coding, review, debug, or setup task. Reads the task context and loads the most relevant skills from sa37.9Kskills.sh installs