
Go dependency injection
Guides Go code toward constructor injection, explicit wiring and no global state
Go dependency injection is an open-source agent skill for developer tools. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.
- Scripts
- None
- Platforms
- Claude Code, Codex, Cursor
- GitHub stars
- 90
- Last commit
- License
- MIT
- Listing updated
Similar skills
About Go dependency injection
This skill teaches an agent to structure Go code around explicit dependency passing. Services receive their collaborators through constructor parameters, and all construction happens in one composition root, usually main or a run function. It walks through removing package-level singletons from legacy code by introducing a struct and a temporary wrapper that is later deleted, and it notes that small seams can be handled by injecting plain functions instead of interfaces.
The skill also gives a decision rule for when a DI framework is worth adding. Manual wiring is the default, google/wire is preferred if code generation becomes necessary, and uber-go/fx or dig are reserved for cases that need a runtime container or lifecycle management. It stresses using only one mechanism per application. A closing checklist lets the agent verify that wiring errors surface at compile time through go build.
The skill is aimed at Go projects and expects the Go toolchain to be installed. Wire and fx are optional. Its allowed tools cover reading and editing files, searching, and running go and gofmt.
When your agent uses it
Dependency injection in Go: constructor injection, wiring in main, avoiding global state, and when frameworks (wire, fx, dig) earn their complexity. Use when: "dependency injection", "wire up dependencies", "inject this", "remove global state", "singleton in Go", "use google/wire", "uber fx", "make this testable". Not for: interface design (go-interface-design), directory structure (go-project-layout), test doubles and mocks (go-test-quality).
From the skill's SKILL.md. Your agent reads this description to decide when to load the skill.
What it can access
- Instructions only, no scripts(see the files on GitHub)
- Asks for: Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(gofmt:*)(see the files on GitHub)
- License: MIT(see the files on GitHub)
From a static check of its 1 file (6 KB) on GitHub on 3 December 2026. Nothing was run. Read the files before you install a skill: it can tell your agent to run anything its tools allow.
Check another skill before you install it.
Install
Download the skill folder from https://github.com/eduardo-sl/go-agent-skills and copy it into your agent's skills folder.
What it does
- Constructor injection pattern
- Shows how to pass dependencies as explicit constructor parameters and validate them.
- Composition root wiring
- Describes building all components in main or a run function in dependency order.
- Removing global state
- Covers migrating package-level singletons to structs with a temporary compatibility wrapper.
- Function-based seams
- Explains injecting small functions such as clocks or ID generators for testability.
- DI framework guidance
- Compares manual wiring, google/wire, uber fx and dig, with a decision rule for choosing.
- DI verification checklist
- Provides a checklist for confirming dependencies are injected and wiring compiles.
Good for
- Refactor a Go service that uses global database variables to take its dependencies through constructors
- Wire up the dependencies of a Go HTTP server in main
- Decide whether a growing Go application should adopt google/wire or stay with manual wiring
- Make a Go package testable by removing package-level singletons
Go dependency injection FAQ
What tools does Go dependency injection need?
It requires the Go toolchain. The wire and fx packages are optional and only needed if you choose to use them.
Does Go dependency injection prescribe a DI framework?
No. It recommends manual wiring by default and only suggests a framework when manual wiring becomes hard to maintain, with wire preferred over fx when generation is needed.
How does Go dependency injection handle legacy global state?
It suggests introducing a struct, keeping a deprecated package-level wrapper that delegates to one instance built in main, moving callers over, and then deleting the wrapper.
Does Go dependency injection run scripts?
No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.
Which AI agents can use Go dependency injection?
Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.
What are the best alternatives to Go dependency injection?
The closest alternatives to Go dependency injection are Go design patterns, Go interface design, Go project layout, Go architecture review and Go coding standards.
Where this comes from
- Description: from the skill's own SKILL.md.
More from eduardo-sl/go-agent-skills

Guides Go agents in designing HTTP REST APIs, handlers, middleware and shutdown
- Open source
- 90 GitHub stars
- Developer tools

Reviews Go project structure, dependency direction and module boundaries
- Open source
- 90 GitHub stars
- Developer tools

Guides an AI agent to build Go command-line tools with clean flags, streams and exit codes
- Open source
- 90 GitHub stars
- Developer tools

Guides Go code toward idiomatic design patterns like functional options and factories
- Open source
- 90 GitHub stars
- Developer tools

Guides building Go GraphQL servers with gqlgen, covering N+1 batching and query limits
- Open source
- 90 GitHub stars
- Developer tools

Guides an AI agent through production gRPC services in Go: protos, errors, streaming
- Open source
- 90 GitHub stars
- Developer tools

