golang-samber-do

Replace manual constructor wiring with samber/do dependency injection in Go.

1|Updated May 27, 2026
One-click install
npx skills add https://github.com/dmwin72015/netdisk --skill golang-samber-do-dmwin72015
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-do
Source: https://github.com/dmwin72015/netdisk/tree/main/.agents/skills/golang-samber-do
Command: npx skills add https://github.com/dmwin72015/netdisk --skill golang-samber-do-dmwin72015

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you eliminate brittle, manual constructor wiring in Go by using samber/do to centralize dependency injection and lifecycle management so services start correctly and are easy to test.

Core Features & Use Cases

  • Type-safe service registration: Register dependencies as interfaces with providers that return (T, error), ensuring failures are handled where they occur.
  • Correct lifecycle control: Use lazy (default), eager, and transient registrations to match startup requirements and per-request behavior.
  • Production-ready container patterns: Organize modules with do.Package, isolate per-request state with scopes, and integrate health checks and graceful shutdown through standard interfaces.

Quick Start

Tell your AI to install samber/do v2, create a do.New() container, register config/db/cache via do.Provide inside modular do.Package() blocks, and invoke services from the composition root with do.MustInvoke while implementing HealthCheck() and Shutdown() on cleanup-needed services.

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 using samber/do?

To set up dependency injection in Go with samber/do, create a container using do.New, register dependencies via do.Provide inside modular do.Package blocks, and invoke services from the composition root using do.MustInvoke. This replaces manual constructor wiring with centralized, type-safe service registration.

What's the best way to manage service lifecycles in a Go service container?

Managing service lifecycles in a Go service container involves using lazy (default), eager, and transient registrations. Lazy delays instantiation until invoked, eager initializes at startup, and transient creates new instances per request, matching specific startup and per-request behaviors.

How do you implement graceful shutdown and health checks in Go applications?

Implement graceful shutdown and health checks in Go applications by integrating do.HealthCheck and injector.ShutdownOnSignalsWithContext from samber/do. Services needing cleanup must implement standard Shutdown and HealthCheck interfaces to ensure proper lifecycle management across server operations.

Does samber/do support scoped dependencies for per-request state in Go?

Yes, samber/do supports scoped dependencies for per-request state in Go. You can use do.Scope to isolate per-request state within the dependency injection container, ensuring that transient or scoped services do not leak data across concurrent server requests.

Why use a dependency injection container instead of manual constructor wiring in Go?

You use a dependency injection container instead of manual constructor wiring in Go to eliminate brittle, hardcoded dependencies. Centralizing service registration via providers ensures failures are handled where they occur, making complex Go applications start correctly and significantly easier to test.

Can I organize Go dependency registrations into modular packages with samber/do?

Yes, you can organize Go dependency registrations into modular packages with samber/do. Using the do.Package function allows you to group related service registrations into cohesive modules, keeping your composition root clean and maintaining strict structural organization across large applications.