golang-uber-dig

Wire Go service dependency graphs with uber-go/dig Provide and Invoke.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you implement dependency injection in Go by wiring complex object graphs with uber-go/dig, so you can avoid tangled constructor signatures and reduce wiring bugs at startup.

Core Features & Use Cases

  • Reflection-based DI container wiring: Use dig.New with Provide/Invoke to register constructors lazily and resolve dependencies during activation.
  • Cleaner composition with parameter and result objects: Use dig.In and dig.Out to group many dependencies and return multiple related values from one constructor.
  • Practical graph disambiguation and aggregation: Use dig.Name to manage multiple providers of the same type, and use value groups (including group flattening) for route handlers, migrations, or worker sets.
  • Safer production behavior: Prefer dig.RecoverFromPanics and dig.DryRun(true) to validate wiring and convert constructor panics into typed failures instead of crashing.
  • Best-practice architecture guidance: Keep the container at the composition root and inject only typed dependencies into business code to preserve testability.

Quick Start

Ask the AI to generate a dig wiring example for your Go service that uses dig.In for a multi-dependency constructor, uses dig.Name for two *sql.DB instances, and validates the graph with dig.DryRun(true) in a unit 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 wire Go dependencies with uber-go/dig?

Wire Go dependencies by registering constructors with dig.New using Provide and Invoke to lazily resolve application object graphs during startup. This avoids tangled constructor signatures and ensures safe activation for CLIs, libraries, and HTTP servers.

What is the best way to group multiple dependencies in a Go DI container?

Group multiple dependencies in a Go DI container by using dig.In for parameter objects and dig.Out for result objects. This allows constructors to cleanly consume many dependencies and return multiple related values from a single function.

How do I provide multiple instances of the same type in a Go dependency graph?

Provide multiple instances of the same type in a Go dependency graph using dig.Name to disambiguate providers. You can also use value groups to aggregate implementations for collections like route handlers, migrations, or worker sets.

Can I validate my Go dependency graph without running the application?

Validate your Go dependency graph without running the application by enabling dig.DryRun(true). Combined with dig.RecoverFromPanics, this converts constructor panics into typed failures, allowing safe startup validation inside unit tests.

When should I use dependency injection in Go?

Use dependency injection in Go when composing application graphs at startup for CLIs, libraries, HTTP servers, or test harnesses. Keep the container at the composition root and inject only typed dependencies into business code to preserve testability.

Does dependency injection with dig work for Go test harnesses?

Dependency injection with dig works effectively for Go test harnesses by registering and resolving test constructors safely. Using dig.DryRun(true) allows you to validate the complete wiring of your test graph without executing actual side effects.