golang-samber-do

Implement type-safe dependency injection in Go using samber/do providers.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps Go developers replace manual constructor wiring with type-safe dependency injection using samber/do, improving modularity, testability, and lifecycle management.

Core Features & Use Cases

  • Service lifecycle management: Register lazy (default), eager, transient, and value services to match initialization and reuse requirements.
  • Provider-based composition: Define services via provider functions returning (T, error) so failures are handled at registration/invocation time.
  • Scoped lifecycles: Create child scopes to prevent request-scoped state from leaking across requests and to organize visibility by module.
  • Operational readiness: Integrate health checks and graceful shutdown through samber/do interfaces and container-driven lifecycle hooks.
  • Maintainable organization: Use do.Package to group infrastructure, domain, and transport registrations cleanly at the composition root.

Quick Start

Use samber/do in your Go codebase to build a root injector and register your services with do.Provide (or do.ProvideValue / do.ProvideTransient as appropriate), then resolve application components from the composition root using do.MustInvoke or do.Invoke.

Frequently Asked Questions about golang-samber-do

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

FAQPage Schema
How do I implement dependency injection in Go using samber/do?

To use dependency injection in Go with samber/do, register services via do.Provide* functions with type-safe generic (T, error) providers, then resolve components from the composition root using do.Invoke or do.MustInvoke.

What's the best way to manage request-scoped lifecycles in a Go application?

Managing request-scoped lifecycles in Go is best handled by creating child scopes from the root injector, which prevents request-scoped state from leaking across requests and organizes service visibility by module.

How do I wire health checks and graceful shutdown into a Go DI container?

Wire health checks and graceful shutdown into a Go DI container by integrating samber/do interfaces and container-driven lifecycle hooks to manage operational readiness and service termination.

Does samber/do support different service initialization lifecycles like eager or transient?

Yes, samber/do supports different service initialization lifecycles, allowing you to register lazy (default), eager, transient, and value services to match specific initialization and reuse requirements.

When should I restrict container access during dependency injection in Go?

Restrict container access to the composition root during dependency injection in Go to ensure correct dependency resolution, maintain modularity, and prevent service locator anti-patterns from spreading across the codebase.

How do I group infrastructure and domain registrations cleanly in a Go DI container?

Group infrastructure, domain, and transport registrations cleanly in a Go DI container by using do.Package at the composition root to organize provider-based service registration by module.