golang-samber-do

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

7|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/Harmeet10000/skills --skill golang-samber-do-harmeet10000
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-do
Source: https://github.com/Harmeet10000/skills/tree/main/skills/backend/Golang/golang-samber-do
Command: npx skills add https://github.com/Harmeet10000/skills --skill golang-samber-do-harmeet10000

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go applications often suffer from tangled dependencies and brittle wiring as projects scale. samber/do provides a type-safe dependency injection container that centralizes providers, enforces interface-driven design, and simplifies lifecycle management across modules.

Core Features & Use Cases

  • Type-safe container with support for Lazy, Eager, Transient, and Value lifecycles to shape initialization and per-request behavior.
  • Implicit aliasing, named services, and modular package registration to enable flexible composition and testing.
  • Use cases include building modular Go applications, swapping implementations for tests, and organizing registrations with scopes.

Quick Start

Create a root injector, register services with do.Provide, and fetch them with do.Invoke to compose a small service graph.

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 type-safe dependency injection in Go?

Type-safe dependency injection in Go is set up by creating a root injector with do.New, registering services using do.Provide variants, and resolving them via do.Invoke or do.MustInvoke to compose a reusable service graph.

What lifecycles does samber/do v2 support for managing service initialization?

samber/do v2 supports Lazy, Eager, Transient, and Value lifecycles for dependency injection. These lifecycles shape service initialization timing and control per-request behavior within the Go service container.

Can I use dependency injection to swap implementations for testing in Go?

Yes, dependency injection enables swapping implementations for testing in Go. Using implicit aliasing and named services within a container allows you to register mock providers and override real services during test scopes.

What is the best way to organize providers across multiple modules in a Go application?

Organizing providers across modules in a Go application is best handled through modular package registration. samber/do v2 uses scopes to enable flexible composition and centralize service registrations without creating tangled dependencies.

Does dependency injection with samber/do work for large modular Go applications?

Dependency injection with samber/do is designed for large modular Go applications. It centralizes providers, enforces interface-driven design, and simplifies lifecycle management across modules to prevent brittle wiring as projects scale.

Why does my Go service container fail when resolving dependencies?

A Go service container fails when resolving dependencies if providers are missing or improperly registered. Use do.MustInvoke to surface initialization errors immediately, ensuring all required services are wired into the container before invocation.