golang-dependency-injection

Guide Go developers in implementing dependency injection patterns.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/nrmnqdds/gomaluum --skill golang-dependency-injection-nrmnqdds
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-dependency-injection
Source: https://github.com/nrmnqdds/gomaluum/tree/main/.agents/skills/golang-dependency-injection
Command: npx skills add https://github.com/nrmnqdds/gomaluum --skill golang-dependency-injection-nrmnqdds

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go developers gain practical guidance for implementing dependency injection, avoiding globals, and selecting the right DI approach for their projects.

Core Features & Use Cases

  • Manual constructor injection: pass dependencies through constructors to keep code testable and free of global state.
  • Library comparisons: evaluate google/wire, uber-go/dig/fx, and samber/do, including when to use each and how to structure packages.
  • Testing and lifecycle: design for mocks, startup/shutdown, and observable lifecycles in Go applications.

Quick Start

Set up a small Go app wiring Config, Database, and a UserService using manual DI in main.

Frequently Asked Questions about golang-dependency-injection

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

FAQPage Schema
How do I implement dependency injection in Go without using global state?▼

Implement dependency injection in Go by passing dependencies through manual constructors. This keeps your code testable and free of global state by explicitly wiring components like Config and Database into services in main.

What is the best way to choose a Go dependency injection library?▼

Compare Go dependency injection libraries by evaluating google/wire for compile-time generation, uber-go/dig or fx for runtime reflection, and samber/do. Choice depends on your application's need for startup speed versus runtime flexibility.

How do I structure mocks for Go dependency injection testing?▼

Structure mocks for Go dependency injection by designing constructors around interfaces. This allows easy substitution of real dependencies with mock implementations during testing, ensuring observable lifecycles and clean startup/shutdown.

When should I avoid using init-based setup for Go dependency injection?▼

Avoid init-based setup for Go dependency injection when you need testable and predictable code. Enforcing best practices means bypassing globals and init functions to explicitly manage component lifecycles and dependencies in main.

Does manual constructor injection in Go support application lifecycle management?▼

Yes, manual constructor injection in Go supports application lifecycle management. It allows you to design for observable lifecycles, ensuring proper startup and shutdown sequences for components like databases and user services.

Can I use google/wire with existing Go projects that use manual DI?▼

Yes, you can use google/wire with existing Go projects. It generates boilerplate code for manual constructor injection, transitioning your project to compile-time dependency injection while maintaining testability.