golang-samber-do

Implements dependency injection in Go projects using the samber/do v2 library.

Updated Jun 8, 2026
One-click install
npx skills add https://github.com/vovanostm-public/multica --skill golang-samber-do-vovanostm-public
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-samber-do
Source: https://github.com/vovanostm-public/multica/tree/main/docs/wiki/architecture/archived-codex-skills/20260525-190000/golang-samber-do
Command: npx skills add https://github.com/vovanostm-public/multica --skill golang-samber-do-vovanostm-public

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires github.com/samber/do/v2, and includes references (resource) components.

What problem does it solve? Setting up dependency injection in Go often leads to tangled manual wiring in main.go, v1/v2 import confusion, and service locator anti-patterns. This Skill guides AI coding agents to configure samber/do v2 correctly, with proper service lifecycles, scopes, and testability. ## Core Features & Use Cases - Service Registration & Lifecycles: Register lazy, eager, transient, and value services, including named services for multiple instances of the same type. - Modular Organization: Group registrations with do.Package and organize services by lifecycle using root containers and child scopes. - Lifecycle & Testing: Implement Healthchecker and Shutdowner interfaces for health checks and graceful shutdown, and use container cloning with overrides for mock-based tests. - Use Case: When refactoring a Go web app from manual DI, use this Skill to register config and logger in the root container, scope per-request services, and shut everything down cleanly on SIGINT. ## Quick Start Ask the agent to set up dependency injection in your Go project with samber/do v2, registering a database, a user service, and graceful shutdown on interrupt signals.

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 dependency injection in Go with samber/do?▼

Install v2 with go get github.com/samber/do/v2, create a container with do.New(), and register services via provider functions using do.Provide. Invoke services at the composition root with do.Invoke or do.MustInvoke.

What is the difference between lazy, eager, and transient services in samber/do?▼

Lazy services (do.Provide default) are created on first request, eager services (do.Eager) are created at container startup, and transient services (do.ProvideTransient) return a new instance on every invocation. Choose based on whether the service must be ready immediately or fresh per use.

How do I register two databases of the same type in samber/do?▼

Use do.ProvideNamed to register each instance under a distinct name such as primary-db and replica-db, then retrieve them with do.MustInvokeNamed. This avoids overwriting registrations and unnecessary wrapper types.

Should I pass the do.Injector into my handlers or services?▼

No. The container should only be accessed at the composition root in main or startup code. Passing the injector into business logic creates a service locator anti-pattern that hides dependencies; resolve dependencies inside provider functions instead.

How do I mock dependencies in tests with samber/do?▼

Clone the production container with injector.Clone(), then replace services using do.Override or do.OverrideValue with mocks. Invoke the service under test from the cloned container so the original stays unaffected.

Does samber/do support health checks and graceful shutdown?▼

Yes. Implement HealthCheck() error on services and call do.HealthCheck to verify them. Implement Shutdown methods and use injector.ShutdownOnSignalsWithContext with os.Interrupt for graceful shutdown with optional timeouts.