golang-samber-do

Featured

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.

AI & Automation 2,108 stars 134 forks Updated 3 days ago MIT

Install

View on GitHub

Quality Score: 98/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

**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...

Details

Author
samber
Repository
samber/cc-skills-golang
Created
2 months ago
Last Updated
3 days ago
Language
Go
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Listed

golang-samber-do

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.

0 Updated today
guynhsichngeodiec
AI & Automation Listed

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.

0 Updated today
guynhsichngeodiec
AI & Automation Featured

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.

2,108 Updated 3 days ago
samber