golang-samber-do

Assemble type-safe Go dependency injection containers with samber/do/v2.

2.9k|191|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-do
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-do
Source: https://github.com/samber/cc-skills-golang/tree/main/skills/golang-samber-do
Command: npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-do

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Dependency injection in Go projects can become boilerplate-prone and hard to test; this skill provides a structured approach using samber/do/v2 to compose services, manage lifecycles, and enable clean testing.

Core Features & Use Cases

  • Type-safe DI container at the composition root with clear lifecycle management (lazy, eager, transient, value)
  • Support for scoped containers, named services, and implicit/explicit aliasing
  • Built-in testing patterns: container cloning and overrides for isolated tests
  • Health checks and graceful shutdown hooks integrated with the DI container
  • Encourages modular package organization via do.Package for infrastructure, domain, and transport layers

Quick Start

Create a root injector with do.New(), register services with do.Provide or do.ProvideValue, and resolve them with do.MustInvoke.

Frequently Asked Questions about golang-samber-do

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

FAQPage Schema
How do I set up a type-safe dependency injection container in Go?

Build a scalable Go dependency injection container by creating a root injector with do.New(), registering services using do.Provide or do.ProvideValue, and resolving them at startup via do.MustInvoke to wire services with type safety.

What is the best way to manage per-service lifecycles in a Go DI container?

Manage per-service lifecycles in a Go DI container by defining explicit providers with lazy, eager, transient, or value scopes. This structured approach handles initialization timing and integrates graceful shutdown hooks for each service.

How do I override dependencies for isolated testing in Golang?

Override dependencies for isolated testing in Golang by cloning your DI container and applying explicit service overrides. This test-ready pattern allows swapping mock implementations without altering the root injector's production providers.

Can I use scoped containers and named services for modular Go architecture?

Yes, you can use scoped containers and named services for modular Go architecture. The DI container supports implicit and explicit aliasing, while do.Package encourages separating infrastructure, domain, and transport layers.

How do you handle graceful shutdown and health checks with dependency injection?

Handle graceful shutdown and health checks with dependency injection by integrating built-in hooks directly into your DI container. This structure manages per-service lifecycles and cleanly orchestrates shutdown procedures across wired services.