golang-dependency-injection

Guides dependency injection in Go with constructor-based wiring and interface-first design.

1|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/dashkan/pivox --skill golang-dependency-injection-dashkan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-dependency-injection
Source: https://github.com/dashkan/pivox/tree/main/.agents/skills/golang-dependency-injection
Command: npx skills add https://github.com/dashkan/pivox --skill golang-dependency-injection-dashkan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Dependency injection removes hidden dependencies and tight coupling in Go code so services become easier to test, evolve, and wire correctly.

Core Features & Use Cases

  • Constructor-based DI: Enforce passing dependencies explicitly and avoid global variables and init-based service setup.
  • Interface-first boundaries: Define interfaces where they are consumed to keep implementation packages clean and decoupled.
  • Library-aware architecture: Choose among google/wire, uber-go/dig+fx, and samber/do based on project size and lifecycle needs, including refactor guidance for existing codebases.

Quick Start

Implement your Go service wiring by selecting manual constructor injection for small graphs, or samber/do for generics-based, lifecycle-friendly DI, then generate the composition code at app startup.

Frequently Asked Questions about golang-dependency-injection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I eliminate global state and init-based wiring in Go services?

Dependency injection in Go eliminates global state and init-based wiring by enforcing explicit constructor injection and consumer-defined interfaces, making services easier to test and evolve. The Skill guides this architectural shift for new and existing Go codebases.

What's the best way to choose a dependency injection library for Go?

Choosing a Go dependency injection library depends on project size and lifecycle needs. The Skill helps you decide between manual constructor injection, google/wire, uber-go/dig+fx, and samber/do to produce correct wiring guidance for your specific architecture.

How do I structure interfaces for dependency injection in Go?

Structure Go interfaces where they are consumed rather than where they are implemented. This interface-first approach keeps implementation packages clean and decoupled, allowing dependency injection to remove hidden dependencies and tight coupling effectively.

Does dependency injection work with shallow dependency graphs in Go?

Yes, dependency injection works with shallow dependency graphs in Go. The Skill requires explicit constructor injection, composition-root-only containers, and shallow dependency graphs, while providing optional lifecycle and lazy initialization practices aligned to your chosen approach.

When should I use samber/do for dependency injection in Go?

Use samber/do for dependency injection when you need generics-based, lifecycle-friendly DI in Go. The Skill recommends it for larger dependency graphs, while advising manual constructor injection for smaller graphs to maintain architecture clarity.

How do I refactor a tightly coupled Go system to use dependency injection?

Refactor coupled Go systems by replacing service-locator patterns and global variables with explicit constructor injection, consumer-defined interfaces, and composition-root-only containers. The Skill provides targeted refactor guidance based on your chosen DI library.