golang-uber-dig

Guide dependency-injection design for Golang projects using uber-go/dig.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-uber-dig-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-uber-dig
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-uber-dig
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-uber-dig-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you design and wire Go applications with uber-go/dig so dependencies stay explicit, startup composition stays clean, and complex object graphs remain testable.

Core Features & Use Cases

  • Parameter Objects: Use dig.In to keep constructors readable when they need many dependencies.
  • Multiple Implementations: Register the same type under different names or expose concrete values as interfaces.
  • Grouped Contributions: Collect many providers into one slice for routers, handlers, or migrations.
  • Scoped Wiring and Decoration: Create child scopes for request- or module-level dependencies and decorate existing values without rewriting constructors.
  • Validation and Safety: Validate graphs with dry runs, handle constructor panics as errors, and keep the container at the composition root.

Quick Start

Use this Skill to review my Go codebase and show how to wire it with uber-go/dig using the right patterns for constructors, scopes, groups, and validation.

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 multiple implementations of the same type in Go dependency injection?

You can register multiple implementations of the same type in Go dependency injection by assigning unique names to providers or exposing concrete values as interfaces using dig.As. This prevents type collisions and clarifies which implementation to inject.

What's the best way to collect multiple providers into a single slice for Golang routers?

The best way to collect multiple providers into a single slice for Golang routers is using value groups. Value groups aggregate many registered providers into one slice, streamlining collection for routers, handlers, or database migrations.

How do I keep Go constructors readable when they require many dependencies?

To keep Go constructors readable when they require many dependencies, use parameter objects with dig.In. This pattern bundles multiple dependencies into a single struct, making constructor signatures clean and maintainable.

Can I validate my Golang dependency injection graph before running the application?

Yes, you can validate your Golang dependency injection graph before running the application by executing a dry run. Dry runs validate the entire object graph to catch missing dependencies and configuration errors safely at startup.

How do I override existing dependencies in a Go application without rewriting constructors?

You can override existing dependencies in a Go application without rewriting constructors by using decorators. Decorators intercept and modify values from existing providers, allowing behavior customization while preserving the original constructor logic.

When should I use scoped wiring for Go dependency injection?

Use scoped wiring for Go dependency injection when you need request- or module-level dependencies. Creating child scopes isolates specific object graphs from the root container, keeping state localized and preventing cross-request leaks.