Golang Dependency Injection
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.
- Type
- Skill
- Author
- samber
- Category
- Backend
- GitHub stars
- 3.7K
- Installs
- 39.6K
- Last updated
- November 1, 2026
Install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-dependency-injectionUse cases
- Design service architecture with constructor injection in Go.
- Refactor tightly coupled code to use dependency injection.
- Compare google/wire, uber-go/dig, uber-go/fx, and samber/do for a project.
Frequently Asked Questions
Why use dependency injection in Go?
It helps with testability, loose coupling, separation of concerns, and lifecycle management.
Does it cover specific DI libraries?
It compares google/wire, uber-go/dig, uber-go/fx, and samber/do, and points to dedicated skills for each.
Does it cover manual injection?
Yes, it covers manual constructor injection alongside the library options.
About this skill
Explains dependency injection in Go, covering why it matters for testability and lifecycle management, manual constructor injection, and comparisons of google/wire, uber-go/dig, uber-go/fx, and samber/do. Useful when designing service architecture, refactoring tightly coupled code, or managing singletons and service factories. Points to dedicated skills for each specific DI library.
Summary written with AI assistance from the project's public description.
Categories
More from samber
Golang Code Style
Golang code style conventions — line length and breaking, variable declarations, control flow clarity, when comments help vs hurt. Use when writing...
by samber
Golang Testing
Production-ready Golang tests — table-driven tests, testify suites and mocks, parallel tests, fuzzing, fixtures, goroutine leak detection with gole...
by samber
Golang Error Handling
Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the si...
by samber
Golang Security
Security best practices and vulnerability prevention for Golang. Covers injection (SQL, command, XSS), cryptography, filesystem safety, network sec...
by samber
Similar Skills
Find Skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", o...
by vercel-labs
Grill Me
A relentless interview to sharpen a plan or design.
by mattpocock
Ai Video Generation
Generate AI videos with Google Veo, Seedance 2.0, HappyHorse, Wan, Grok and 40+ models via inference.sh CLI. Models: Veo 3.1, Veo 3, Seedance 2.0,...
by inference-sh
Ai Image Generation
Generate AI images with GPT-Image-2, FLUX, Gemini, Grok, Seedream, Reve and 50+ models via inference.sh CLI. Models: GPT-Image-2, FLUX Dev LoRA, FL...
by inference-sh