golang-samber-do

Set up type-safe dependency injection for Go applications with samber/do v2.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-samber-do-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-do
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-samber-do
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-samber-do-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you replace ad hoc constructor wiring with a clean, type-safe dependency injection setup in Go, using samber/do v2 to manage service creation and dependencies.

Core Features & Use Cases

  • Container setup and composition root guidance for Go applications.
  • Service registration patterns for lazy, eager, transient, named, and value-based services.
  • Lifecycle support for scopes, health checks, graceful shutdown, struct injection, and test-time overrides.
  • Useful for production APIs that need modular service organization, isolated request state, and reliable startup or teardown behavior.

Quick Start

Ask me to wire samber/do v2 into your Go project and I will show the correct container setup, service registrations, and lifecycle patterns for your use case.

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, you create a service container using do.New, register dependencies via providers, and resolve them through implicit aliasing or named services for modular organization.

What is the best way to manage service lifecycles and graceful shutdown in a Go API?

Managing service lifecycles and graceful shutdown in a Go API involves using a service container to register scoped dependencies, enabling health checks and reliable teardown behavior during application startup and exit.

Can I override dependencies for testing in Go applications with samber/do?

Yes, you can override dependencies for testing in Go applications using samber/do by registering test-time overrides in the service container, allowing you to isolate request state and mock modular services easily.

Does samber/do support lazy loading and transient service registration in Go?

Yes, samber/do supports lazy loading and transient service registration in Go, allowing the service container to instantiate dependencies on demand or provide fresh instances per resolution request.

How do I use struct injection to organize modular packages in a Go application?

You use struct injection in a Go application to automatically populate struct fields with dependencies from the service container, ensuring modular package organization and clean composition root wiring.

When should I use named services instead of implicit aliasing in Go dependency injection?

You should use named services in Go dependency injection when registering multiple implementations of the same interface, and rely on implicit aliasing for standard default type-safe wiring.