golang-uber-dig

Automate Go dependency injection wiring with uber-go/dig containers.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It eliminates brittle, manual construction of complex Go object graphs by letting you declaratively wire dependencies and have dig resolve them safely at composition time.

Core Features & Use Cases

  • Lazy, memoized construction: Use constructors with Provide so each dependency is built once per container and reused where needed.
  • Clean parameter/result wiring: Use dig.In/dig.Out to manage many dependencies, including named values, value groups, and optional dependencies.
  • Disambiguation and interface exposure: Use dig.Name to select between multiple values of the same type and dig.As to expose concrete implementations only through interfaces.
  • Graph validation and error clarity: Validate wiring early with DryRun(true) and get dependency-path error messages when Invoke fails.
  • Scope-local composition: Create child scopes for request/tenant/module boundaries so per-request values don’t leak across concurrent executions.
  • Testing-friendly DI: Build fresh containers per test, override providers via decoration, and validate graphs without running side-effecting constructors.

Quick Start

Use the golang-uber-dig skill to wire an HTTP service where many route constructors automatically contribute handlers into a routes group consumed by a single server constructor, ensuring missing providers fail at startup.

Frequently Asked Questions about golang-uber-dig

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

FAQPage Schema
How do I automate Go dependency injection wiring for services with many constructors?

Automate Go dependency injection wiring by using a dig.Container at the composition root to safely resolve complex object graphs during application startup. You define constructors that return types and errors, and dig handles lazy, memoized construction so each dependency is built once and reused.

What is the best way to manage many Go dependencies including named values and optional dependencies?

Manage many Go dependencies by embedding dig.In and dig.Out structs within your constructor parameters and results. This allows you to declaratively wire named values, value groups, and optional dependencies using struct tags, keeping construction clean and preventing brittle manual wiring.

How does dependency graph validation work with uber-go/dig during application startup?

Dependency graph validation works by running DryRun(true) on the dig.Container to validate wiring early without executing side-effecting constructors. When Invoke fails, dig provides clear dependency-path error messages to pinpoint missing providers during application startup.

Can I expose concrete Go implementations only through interfaces using dig?

Yes, you can expose concrete Go implementations only through interfaces using the dig.As tag. This disambiguation technique ensures modular boundaries are respected, allowing you to select between multiple values of the same type while preventing direct access to underlying concrete structs.

How do I prevent per-request values from leaking across concurrent executions in Go dependency injection?

Prevent per-request values from leaking by creating child scopes from the dig.Container for request, tenant, or module boundaries. This scope-local composition ensures isolated dependency graphs for concurrent executions, keeping request-scoped values contained.

Does dependency injection with dig work for building fresh containers and overriding providers in tests?

Yes, dependency injection with dig supports testing-friendly DI by allowing you to build fresh containers per test and override providers via decoration. You can validate object graphs without running side-effecting constructors, ensuring reliable and isolated test environments.