golang-samber-do
Dependency injection in Golang using samber/do — service containers, lifecycle management, scopes, health checks, graceful shutdown, and module organization. Apply when using or adopting samber/do, when the codebase imports github.com/samber/do or github.com/samber/do/v2, or when refactoring manual constructor injection into a DI container.
Security Assessment
About golang-samber-do
This skill provides structured guidance for using dependency injection in Go with the samber/do v2 library. It helps developers organize application dependencies through a central injector (container), replacing manual constructor wiring with a controlled composition root. The approach improves modularity, testability, and lifecycle management by ensuring that services are created, resolved, and shared in a consistent and predictable way. Instead of tightly coupling components, services are registered with provider functions and resolved through the injector when needed.
The core capabilities include multiple service registration modes such as lazy (created on first use), eager (initialized immediately), transient (new instance per request), and value-based services (pre-instantiated objects). It supports typed provider functions that return a service instance and optional error, enabling safe construction of dependencies. The skill also emphasizes implicit dependency resolution through functions like Invoke and MustInvoke, including typed resolution, named services for multiple instances of the same type, and implicit aliasing where concrete types can be resolved as interfaces without explicit mapping. The injector is intended to remain at the composition root, ensuring dependency resolution does not leak throughout the application.
This skill is designed for Go engineers working with modern Go (1.18+) applications, particularly those adopting samber/do v2 for dependency injection. It is useful in backend services, microservices, and modular monoliths where clean separation of concerns and lifecycle management are important. It is especially relevant for teams refactoring legacy codebases that use manual constructor injection or global state, as it provides a structured migration path toward container-based dependency management while preserving type safety and explicit error handling.
FAQ
What problem does samber/do solve in Go applications?
It replaces manual dependency wiring with a centralized injector that manages service creation, lifecycle, and resolution in a type-safe way.
What service lifecycle types are supported?
Lazy (default), eager, transient, and value-based services are supported to control how and when dependencies are instantiated.
Can interfaces be resolved directly without explicit binding?
Yes, implicit aliasing allows concrete types to be registered and later resolved as interfaces using typed invocation.
Where should the injector be used in an application?
The injector should be used only at the composition root to assemble dependencies, not throughout the business logic.
Does the library support multiple implementations of the same type?
Yes, named services allow multiple instances of the same type to be registered and retrieved using unique identifiers.
Install golang-samber-do
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
samber/cc-skills-golang