golang-uber-dig

Implements dependency injection in Go applications using the uber-go/dig reflection-based container.

1|Updated Jun 2, 2026
One-click install
npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-uber-dig-verifiedorganic
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-uber-dig
Source: https://github.com/VerifiedOrganic/onboard/tree/main/.agents/skills/golang-uber-dig
Command: npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-uber-dig-verifiedorganic

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Wiring a Go application's object graph by hand leads to tangled constructors, duplicated initialization logic, and missing-dependency failures that only surface at runtime. This Skill guides an AI agent to wire applications correctly with uber-go/dig, covering Provide/Invoke, parameter and result objects, named values, value groups, scopes, and decorators. ## Core Features & Use Cases - Container Wiring Patterns: Register lazy, memoized constructors with Provide and resolve graphs with Invoke, using dig.In/dig.Out structs, named values, value groups with flatten, and dig.As to expose interfaces. - Advanced Graph Management: Apply Decorate for cross-cutting changes, child Scopes for request-local dependencies, optional dependencies, DryRun graph validation, and DOT visualization of failed wiring. - Testing and Validation: Build per-test containers, override providers with Decorate, and validate the production graph in CI without running real constructors. - Use Case: You have two *sql.DB connections (primary and read replica) and several HTTP handlers. The Skill shows how to disambiguate the databases with dig.Name and collect all handlers into a router with a value group, with no manual slice assembly in main(). ## Quick Start Ask the agent to wire your Go service's constructors with uber-go/dig using parameter objects and value groups, then validate the graph with a DryRun test.

Frequently Asked Questions about golang-uber-dig

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

FAQPage Schema
How do I use uber-go/dig for dependency injection in Go?▼

Create a container with dig.New(), register constructors with c.Provide, and resolve the graph with c.Invoke. Constructors are lazy and memoized, so each output type is built once and shared as a singleton per container.

What is the difference between uber-go/dig and uber-go/fx?▼

fx is built on dig and shares the same DI primitives, but adds lifecycle hooks, modules, signal-aware Run(), and startup timeouts. Choose dig for CLI tools and libraries; choose fx for long-running services needing graceful shutdown.

How do I register two instances of the same type in dig?▼

Use dig.Name("primary") and dig.Name("readonly") as Provide options to disambiguate same-typed providers, or tag fields in a dig.Out result struct. Consumers then add matching name tags to their dig.In fields.

How do I collect multiple handlers into one slice with dig?▼

Tag each constructor's result field with group:"routes" in a dig.Out struct, then consume a []Route field tagged with the same group in dig.In. Note that group order is not guaranteed; use flatten to unwrap slice results.

How do I test dig wiring without starting real services?▼

Build the container with dig.New(dig.DryRun(true)), register the same providers as production, and call Invoke on the composition root. This validates the graph structurally without executing constructors or opening connections.

Should I pass the dig container into my services?▼

No. Keep the container at the composition root in main() and inject typed dependencies into constructors instead. Passing *dig.Container into business code creates a service-locator anti-pattern that hides dependencies and hurts testability.