← ClaudeAtlas

golang-samber-dolisted

Implements dependency injection in Golang using samber/do. Apply this skill when working with dependency injection, setting up service containers, managing service lifecycles, or when you see code using github.com/samber/do/v2. Also use when refactoring manual dependency injection, implementing health checks, graceful shutdown, or organizing services into scopes/modules.
guynhsichngeodiec/cc-skills-golang · ★ 0 · AI & Automation · score 78
Install: claude install-skill guynhsichngeodiec/cc-skills-golang
**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:** - [pkg.go.dev/github.com/samber/do/v2](https://pkg.go.dev/github.com/samber/do/v2) - [do.samber.dev](https://do.samber.dev) - [github.com/samber/do/v2](https://github.com/samber/do) This skill is not exhaustive. Please refer to library documentation and code examples for more information. Context7 can help as a discoverability platform. DO NOT USE v1 OF THIS LIBRARY. INSTALL v2 INSTEAD: ```bash go get -u github.com/samber/do/v2 ``` ## Core Concepts ### The Injector (Container) ```go import "github.com/samber/do/v2" injector := do.New() ``` ### 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: ```go type Provider[T any] func(i Injector) (T, error) ``` ## Basic Usage ### 1. Define and Register Services Follow "Accept Interfaces, Return Structs": ```go // Register a service (lazy by default) do.Provide(injector, func(i do.Injector) (Database, error) { return