golang-dependency-injection

Installation
SKILL.md

Adapted from samber/cc-skills-golang@golang-dependency-injection. Pair with golang-common-practice for shared verification guidance.

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.

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): map three things — (1) global variables and init() service setup, (2) concrete type dependencies that should become interfaces, (3) service-locator anti-patterns (container passed as argument) — then propose a scoped migration plan.

Dependency Injection in Go

Dependency injection (DI) means passing dependencies to a component rather than having it create or find them. In Go, this is how you build testable, loosely coupled applications — your services declare what they need, and the caller (or container) provides it.

This skill is not exhaustive. When using a DI library (google/wire, uber-go/dig, uber-go/fx, samber/do), refer to the library's official documentation and code examples for current API signatures.

For interface-based design foundations (accept interfaces, return structs), see the golang-structs-interfaces skill.

Best Practices Summary

Installs
11
Repository
bateau84/skills
First Seen
13 days ago