samber/do says it has no dependencies, and go.mod requires four
⚙️ A dependency injection toolkit based on Go 1.18+ Generics.
At a glance
- What is it?
- A Go 1.18+ dependency injection toolkit built on generics, pitched as a possible replacement for uber/dig, with eager, lazy and transient services, a scope tree and a web UI with one middleware per framework. The dependency-free claim does not survive contact with the manifest, and the release guarantee stops at v3.0.0.
- Who is it for?
- Adopt samber/do if you want dependency injection resolved by the compiler rather than by reflection, you are starting a new module rather than migrating one, and you can live with a v2 whose stated stability guarantee runs to v3.0.0.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 10 days ago.
- What is it written in?
- Mainly Go, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- samber/do2,840 ★ · +26
| Repository | 2026-09-28 | 2026-11-15 |
|---|---|---|
| samber/do | 2.8k | 2.8k |
26 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
No dependencies except the standard library, except for four modules
The claim is in the install section, stated flatly: this library has no dependencies except the Go std lib. The manifest says otherwise.
require (
github.com/samber/go-type-to-string v1.8.0
github.com/stretchr/testify v1.12.1
go.uber.org/goleak v1.2.1
)Two of those are test-only, testify for assertions and goleak for detecting leaked goroutines. The first is not: `github.com/samber/go-type-to-string` sits in the main require block with no `// indirect` marker, and a package that formats Go types for strings has a plausible use inside a container that resolves services by name.
There is also an indirect requirement on `go.yaml.in/yaml/v3`, which arrives by someone else's dependency graph and is not the standard library either.
And between the `go 1.18` line and the require block the manifest carries an unexplained comment: dependencies are excluded from releases, please check CI.
The project is not ignoring its own graph, incidentally. There is an `audit` target that tidies the module and pipes `go list -json -m all` through `nancy sleuth`, a vulnerability scanner, so the repository scans a dependency set it says it does not have.
Four ways to invoke, and aliasing is a separate axis
The feature list organises invocation into four modes, and the distinction matters because they have different lifetimes.
Eager loading constructs the service at registration or container build time. Lazy loading constructs it on first use. Transient loading constructs a new instance per resolution rather than reusing one. Tag-based invocation is the fourth, and it is not a lifetime at all: it selects a subset of the registered services by tag, which is how you resolve a group rather than a single dependency.
Circular dependency detection is listed alongside them, and it is the feature with the clearest reason to exist. A container that resolves by type can build a cycle at runtime, and a library whose stated goal is compile-time type safety still needs a runtime check for that one case.
Aliasing is kept separate from invocation, in two forms. Implicit aliasing provides a struct and invokes an interface. Explicit aliasing provides a struct, binds an interface, and invokes the interface. So the question of what a service is and the question of what type you ask for are independent decisions, which is what lets you swap an implementation without touching every consumer.
Scopes are a tree with visibility control, and virtual scopes sit beside root
The scope tree is described as a scope tree, also called a module tree, with two properties: visibility control and dependency grouping.
The source layout shows how that is implemented. Three files carry it: `root_scope.go` for the default container's root scope, `scope.go` for the type itself, and `virtual_scope.go` for scopes that are not backed by a real object. Container features listed alongside it are cloning, dependency graph resolution and visualisation, the default container, and service override.
So a scope is a boundary you can nest, and cloning plus override are the operations that make the boundary useful: a test can take the container your application built, clone it, and replace one service without reconstructing the graph.
The `examples/` directory makes the feature list concrete, and one entry maps directly to this section: `nested-scope`. Others cover eager-loading, transient-services, service-aliases, interface, struct, package-system, simple, healthcheckable, shutdownable, event-driven, dag, http, web-application and service-explanation. Fifteen example projects for a library that describes itself as lightweight is a deliberate choice, and it is the clearest inventory of what the library thinks its own surface is.
The web UI ships one HTTP middleware per framework
Debugging and introspection is a first-class feature group, not an afterthought, and it comes in two forms.
The first is a set of Explain APIs that return the scope tree and the service dependencies as data. That is the version you can assert on in a test or print in a terminal, and it is the more useful of the two for a library that prides itself on types.
The second is a web UI, with HTTP middleware listed for the standard library and for four frameworks: Gin, Fiber, Echo and Chi. Five integrations for one diagnostic view, which is the cost of not wanting to own your router.
The `http/` directory at the root is where that lives, and the `dag.go` and `di_explain.go` files are the graph resolution and explanation side. There are matching examples: `examples/http`, `examples/dag` and `examples/service-explanation`.
Worth noting next to this is the `stacktrace/` directory. A container that reports a resolution failure is more useful when it can say where each service was registered, so capturing where a service came from is part of the design rather than an extra.
Every root source file has a test and a runnable example beside it
The repository root is flat, and the naming convention is systematic. Seventeen source files sit directly in the root: `dag.go`, `di.go`, `di_explain.go`, `di_lifecycle.go`, `errors.go`, `injector.go`, `invoke.go`, `root_scope.go`, `scope.go`, `service.go`, `service_alias.go`, `service_eager.go`, `service_lazy.go`, `service_transient.go`, `utils.go`, `virtual_scope.go`, and `main_test.go`.
Each has a `_test.go` sibling, and most have an `_example_test.go` sibling as well, which is Go's convention for documentation that is compiled and run so it cannot rot.
The test commands follow the same thoroughness:
test:
go test -race ./...
watch-test:
reflex -t 50ms -s -- sh -c 'gotest -race ./...'
coverage:
go test -v -coverprofile=cover.out -covermode=atomic ./...The race detector is on by default, not opt-in, and `goleak` is a declared dependency, so a leaked goroutine fails the suite rather than accumulating. For a container that starts health checks and shutdown work, that is the right default.
The `bench/` directory and the `bench` and `watch-bench` targets, which run with `-benchmem -count 3`, are there for the resolution path. `bearer.yml` in the root is a secrets scanner configuration, which is an odd file to find next to a stack trace package and an easy one to explain.
Two module paths, and the stability promise stops at v3.0.0
Installation is three lines, and two of them are for different major versions:
# v2 (latest)
go get github.com/samber/do/v2@latest
# v1
go get github.com/samber/[email protected]
# AI Agent Skill
npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-doThe v1 line is still documented with a pinned version, and a separate migration guide from v1 to v2 is published on the documentation site. So both import paths are live, and the older one has a specific last version rather than an open range.
The manifest agrees with the install line: the module path is `github.com/samber/do/v2`, with `go 1.18` as the language floor, matching the generics-based positioning.
On stability the README makes two commitments. This library is v2 and follows SemVer strictly, and no breaking changes will be made to exported APIs before v3.0.0. That is a promise about exported API shape, not about behaviour, and it is scoped to a future major version that has no date.
The release list fits that: v2.1.0 on 2026-07-20, v2.0.0 on 2025-09-21, and a v2.0.0-rc1 on 2025-08-22 before it. The last push was on 2026-09-24, two months after the newest tag.
The documentation site is a Node app, and the tools are installed unpinned
Two things in the tree explain how this project is worked on.
The first is that the documentation site is a separate Node project. There is a `vercel.json` at the root and a Makefile target that changes into `docs/` and runs npm:
doc:
cd docs && npm install && npm startSo the Go module publishes a GoDoc site at pkg.go.dev, and the prose documentation is built and deployed somewhere else. The README links both, plus a documentation site, an examples directory in the repository, and a separate project templates page pointing at three starter repositories: an API template, a worker template and a CLI template.
The second is the `tools` target, which installs seven tools and ends by rewriting the manifest:
tools:
go install github.com/cespare/reflex@latest
go install github.com/rakyll/gotest@latest
go install github.com/psampaz/go-mod-outdated@latest
go install github.com/jondot/goweight@latestEvery one is `@latest`, and the target finishes with `go mod tidy`. So the development toolchain is not reproducible even though the library itself is, which is the usual trade and worth knowing before a build failure turns out to be a tool version.
The last details are small and telling. The name is explained as the sum of `DI` and `Go`, chosen because no Go package uses it. The author's other libraries are linked as siblings, `ro`, `lo` and `mo`, and one of the install lines adds an AI agent skill for the library. The licence is MIT, copyright 2022 Samuel Berthe.
Editorial conclusion
Adopt samber/do if you want dependency injection resolved by the compiler rather than by reflection, you are starting a new module rather than migrating one, and you can live with a v2 whose stated stability guarantee runs to v3.0.0. Do not adopt it on the strength of the dependency-free claim: the README says there are no dependencies except the Go standard library, while go.mod requires samber/go-type-to-string directly, plus testify and goleak for tests and a YAML module indirectly. Verify which module path you import first, because v1 and v2 are separate paths with a published migration between them, then check that the lifetimes the README lists match what your composition needs, since eager, lazy, transient and tag-based invocation are four different behaviours.
Frequently asked questions
What is samber/do?
It is a dependency injection toolkit for Go built on Go 1.18+ generics, described as a possible replacement for uber/dig with a type-safe API instead of reflection. The name is explained as the sum of DI and Go, chosen because no Go package uses it.
How do you install samber/do?
For the current major version, `go get github.com/samber/do/v2@latest`. The previous line is still documented at `go get github.com/samber/[email protected]`, and a migration guide from v1 to v2 is published on the documentation site.
Which service lifetimes does samber/do support?
Eager loading, lazy loading and transient loading, plus tag-based invocation and circular dependency detection. Service aliasing is a separate axis: implicit, providing a struct and invoking an interface, or explicit, providing a struct, binding an interface and invoking the interface.
Does samber/do ship a web UI for inspecting the container?
Yes. The debugging and introspection features include Explain APIs for the scope tree and service dependencies, a web UI, and HTTP middleware for the standard library, Gin, Fiber, Echo and Chi.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/samber-do)Star history chart for your README
[](https://hysenlabs.com/projects/samber-do)Was this useful?