golang-dependency-injection

Design dependency injection wiring for Go service architectures.

1|Updated May 26, 2026
One-click install
npx skills add https://github.com/tokiou/caba-inseguridad-v2-be --skill golang-dependency-injection-tokiou
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-dependency-injection
Source: https://github.com/tokiou/caba-inseguridad-v2-be/tree/main/.claude/skills/golang-dependency-injection
Command: npx skills add https://github.com/tokiou/caba-inseguridad-v2-be --skill golang-dependency-injection-tokiou

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Dependency injection (DI) prevents Go code from being tightly coupled to concrete dependencies by making dependencies explicit and centrally wired, improving testability and maintainability.

Core Features & Use Cases

  • Manual constructor injection for small projects, with clear wiring order from infrastructure to transport.
  • DI library selection guidance across google/wire, uber-go/dig+fx, and samber/do based on project size, lifecycle needs, and type-safety preferences.
  • Refactoring patterns for removing globals and init-based service setup, plus migration advice away from service-locator anti-patterns (passing containers/injectors into services).

Quick Start

Use the skill to design your Go service wiring by explicitly injecting database and logger dependencies via constructors or by selecting a DI library appropriate to your lifecycle and team constraints.

Frequently Asked Questions about golang-dependency-injection

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

FAQPage Schema
How do I use dependency injection in Go to improve service testability?

Dependency injection in Go improves testability by making dependencies explicit and centrally wired, eliminating hidden dependencies through constructor-based injection at the composition root and using interfaces at consumption boundaries.

What is the best way to choose a Go dependency injection library for lifecycle management?

Choosing a Go dependency injection library depends on project size and type-safety preferences. Select google/wire for compile-time safety, uber-go/dig+fx for lifecycle management, or samber/do for lifecycle-aware dependency graphs.

How do I refactor Go code to remove globals and init-based service setup?

Refactor Go code by removing globals and init-based service setup through manual constructor injection, migrating away from service-locator anti-patterns, and ensuring no container injection occurs directly into services.

When do I need transient or singleton lifecycles in Go dependency injection?

You need singleton or transient lifecycles in Go dependency injection when managing stateful dependencies, utilizing lazy initialization guidance for lifecycle-aware dependency graphs to optimize resource allocation and application startup.

Does dependency injection work with manual wiring for small Go projects?

Yes, dependency injection works with manual wiring for small Go projects by applying manual constructor injection, establishing clear wiring order from infrastructure to transport without requiring a dedicated DI container.