samber/cc-skills-golang/golang-samber-do
Claude Code and agent skill by samber/cc-skills-golang
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Dependency injection in Golang using samber/do — service containers, lifecycle management, scopes, health checks, graceful shutdown, and module organization. Apply when using or adopting samber/do, when the codebase imports github.com/samber/do or github.com/samber/do/v2, or when refactoring manual constructor injection into a DI container.
Install
npx vskill@latest install samber/cc-skills-golang/golang-samber-doSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as samber/cc-skills-golang/golang-samber-do.
Persona: You are a Go architect setting up dependency injection. You keep the container at the composition root, depend on interfaces not concrete types, and treat provider errors as first-class failures.
Using samber/do for Dependency Injection in Go
Type-safe dependency injection toolkit for Go based on Go 1.18+ generics.
Official Resources:
This skill is not exhaustive — refer to library documentation and code examples for more information:
- For Go package docs, symbols, versions, importers, and known vulnerabilities, → See
samber/cc-skills-golang@golang-pkg-go-devskill (godig), preferred over Context7 for Go package facts. - To navigate this library's usage in your own code (definitions, call sites, diagnostics), → See
samber/cc-skills-golang@golang-goplsskill (gopls). - Context7 remains a fallback for docs not indexed on pkg.go.dev.
Install v2 — v1 is superseded and lacks the generics-based container, scopes, and lifecycle hooks documented below, so v1-era guidance misleads on every API in this skill:
Core Concepts
The Injector (Container)
Service Types
- Lazy (default): Created when first requested
- Eager: Created immediately when the container starts
- Transient: New instance created on every request
- Value: Pre-created value, no instantiation
Provider Functions
Services MUST be registered via provider functions:
Basic Usage
1. Define and Register Services
Follow "Accept Interfaces, Return Structs":
2. Invoke Services
The container MUST only be accessed at the composition root:
Inside a provider function, always use do.MustInvoke (or MustInvokeAs/MustInvokeNamed/MustInvokeStruct) rather than the error-returning variant:
- A provider already returns
(T, error), so propagating a dependency failure withdo.Invokecosts an extraif err != nil { return nil, err }on every call. do.MustInvokepanics instead, but samber/do correctly catches and recovers that panic at the enclosingInvokecall and converts it back into a regular error — this recover happens inside the library itself, not in caller code, soMustInvokeis safe to use inside providers.- The failure still surfaces as an error at the composition root, just without the manual boilerplate in every provider.
3. Service Dependencies
4. Implicit Aliasing (Preferred)
Register a concrete type and invoke as an interface without explicit aliasing:
5. Named Services
Register multiple services of the same type:
Package Organization
Use do.Package() to organize service registration by module:
Full Application Setup
Best Practices
- Depend on interfaces, not concrete types — lets you swap implementations in tests without touching production code
- Each service should have one job — services with multiple responsibilities are harder to test and harder to replace
- Keep dependency trees shallow — chains beyond 3-4 levels make initialization order fragile and errors harder to trace
- Handle errors in provider functions — a silently failing provider creates a broken service that crashes later in unexpected places
- Use scopes to organize services by lifecycle — request-scoped services prevent leaks, global services prevent redundant initialization
- Use
do.MustInvoke*inside provider functions instead ofdo.Invoke*— samber/do correctly catches and recovers the panic at the outerInvokecall, turning it back into a returned error, so it's safe to use inside providers and you get the same error propagation without the boilerplate
For scopes, lifecycle management, struct injection, and debugging, see Advanced Usage.
For testing patterns (cloning, overrides, mocks), see Testing.
Quick Reference
Registration
| Function | Purpose | |
|---|---|---|
do.Provide[T]() | Register lazy service (default) | |
do.ProvideNamed[T]() | Register named lazy service | |
do.ProvideValue[T]() | Register pre-created value | |
do.ProvideNamedValue[T]() | Register named value | |
do.ProvideTransient[T]() | Register new instance each time | |
do.ProvideNamedTransient[T]() | Register named transient service | |
do.Package() | Group service registrations |
Invocation
| Function | Purpose | |
|---|---|---|
do.Invoke[T]() | Get service (with error) | |
do.InvokeNamed[T]() | Get named service | |
do.InvokeAs[T]() | Get first service matching interface | |
do.InvokeStruct[T]() | Inject into struct fields using tags | |
do.MustInvoke[T]() | Get service (panic on error) | |
do.MustInvokeNamed[T]() | Get named service (panic on error) | |
do.MustInvokeAs[T]() | Get service by interface (panic on error) | |
do.MustInvokeStruct[T]() | Inject into struct (panic on error) |
Cross-References
- → See
samber/cc-skills-golang@golang-dependency-injectionskill for DI concepts, comparison, and when to adopt a DI library - → See
samber/cc-skills-golang@golang-structs-interfacesskill for interface design patterns - → See
samber/cc-skills-golang@golang-testingskill for general testing patterns
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/golang-samber-do/SKILL.md
Popularity
- Repository stars
- 3,336
- Repository forks
- 219
- 7-day trend score
- 41
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 25 Mar 2026, 8 months ago.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/samber/cc-skills-golang/golang-samber-do)