golang-uber-dig

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

Updated Jun 8, 2026
One-click install
npx skills add https://github.com/vovanostm-public/multica --skill golang-uber-dig-vovanostm-public
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-uber-dig
Source: https://github.com/vovanostm-public/multica/tree/main/docs/wiki/architecture/archived-codex-skills/20260525-190000/golang-uber-dig
Command: npx skills add https://github.com/vovanostm-public/multica --skill golang-uber-dig-vovanostm-public

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires go.uber.org/dig, and includes references (resource) components.

What problem does it solve? Wiring a Go application's object graph by hand leads to tangled constructors, duplicated initialization code, and missing-dependency failures discovered only at runtime. This Skill guides AI agents to wire dependencies correctly with uber-go/dig, covering containers, constructors, parameter objects, named values, value groups, scopes, and decorators. ## Core Features & Use Cases - Container Wiring: Register lazy, memoized constructors with Provide and resolve graphs with Invoke, keeping the container at the composition root. - Advanced DI Patterns: Use dig.In/dig.Out parameter and result objects, named values for multiple instances of one type, value groups with flatten, dig.As to expose interfaces, and Decorate for cross-cutting behavior. - Testing & Validation: Validate the production graph in CI with DryRun, detect cycles, recover constructor panics as typed errors, and visualize failed graphs in DOT format. - Use Case: When a Go service needs two *sql.DB connections (primary and read replica), the Skill shows how to register both with dig.Name and consume them via name tags instead of wrapper types. ## Quick Start Ask the agent to wire your Go application's dependencies with uber-go/dig, for example by registering constructors for config, logger, database, and server and resolving the graph with Invoke in main.

Frequently Asked Questions about golang-uber-dig

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

FAQPage Schema
How do I handle a Go constructor with many dependencies in uber-go/dig?▼

Embed dig.In in a parameter struct and pass it as the constructor's single argument. Each field becomes a dependency the container fills automatically, and adding a new dependency is a one-line change instead of a signature break.

How do I register two databases of the same type with uber-go/dig?▼

Use dig.Name("primary") and dig.Name("readonly") as Provide options, or name tags on a dig.Out result struct. Consumers then add name:"primary" or name:"readonly" tags to dig.In fields to receive the right instance.

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

fx is built on dig and shares the same container engine and DI primitives. fx adds lifecycle hooks, a module system, signal-aware Run, and startup timeouts, while dig provides only the wiring graph for apps managing their own lifecycle.

How do I validate a dig dependency graph without running constructors?▼

Create the container with dig.New(dig.DryRun(true)), register the same providers as production, and call Invoke on the composition root. dig validates types structurally without executing constructors, catching missing providers in CI.

Should I pass the dig container into my services?▼

No. The container belongs only at the composition root in main. Inject typed dependencies as constructor parameters instead, since passing the container creates a service-locator anti-pattern that hides dependencies and breaks testability.

How do I collect many handlers into one slice with uber-go/dig?▼

Tag each handler's dig.Out field with group:"routes" and consume a []Handler field tagged with the same group in dig.In. Group order is not guaranteed, so provide an explicit ordered slice from one constructor when ordering matters.