https://github.com/samber/do
⚙️ A dependency injection toolkit based on Go 1.18+ Generics.
https://github.com/samber/do
container dependency dependency-graph di generics go golang graceful-shutdown healthcheck injection injector invoke ioc lifecycle provide service typesafe
Last synced: 10 days ago
JSON representation
⚙️ A dependency injection toolkit based on Go 1.18+ Generics.
- Host: GitHub
- URL: https://github.com/samber/do
- Owner: samber
- License: mit
- Created: 2022-05-17T22:10:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2026-11-05T12:41:07.000Z (23 days ago)
- Last Synced: 2026-11-13T13:38:43.904Z (15 days ago)
- Topics: container, dependency, dependency-graph, di, generics, go, golang, graceful-shutdown, healthcheck, injection, injector, invoke, ioc, lifecycle, provide, service, typesafe
- Language: Go
- Homepage: https://do.samber.dev
- Size: 8.31 MB
- Stars: 2,840
- Watchers: 20
- Forks: 113
- Open Issues: 65
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - samber/do - ⚙️ A dependency injection toolkit based on Go 1.18+ Generics. (Go)
- awesome-go - do - A dependency injection framework based on Generics. (Miscellaneous / Dependency Injection)
- awesome-go-cn - do
- my-awesome - samber/do - topic:container,dependency,dependency-graph,di,generics,go,golang,graceful-shutdown,healthcheck,injection,injector,invoke,ioc,lifecycle,provide,service,typesafe pushed\_at:2026-11 star:2.8k fork:0.1k ⚙️ A dependency injection toolkit based on Go 1.18+ Generics. (Go)
- zero-alloc-awesome-go - do - A dependency injection framework based on Generics. (Miscellaneous / Dependency Injection)
- awesome-go-extra - do - ⚙️ A dependency injection toolkit based on Go 1.18+ Generics. (Microsoft Office / Dependency Injection)
- awesome-go - do - A dependency injection framework based on Generics. (Miscellaneous / Dependency Injection)
- awesome-go-plus - do - A dependency injection framework based on Generics.  (Miscellaneous / Dependency Injection)
- awesome-go - do - A dependency injection framework based on Generics. (Miscellaneous / Dependency Injection)
- fucking-awesome-go - do - A dependency injection framework based on Generics. (Miscellaneous / Dependency Injection)
- awesome-go-cn - do - **star:2622** A dependency injection framework based on Generics. [\!\[godoc\]\[D\]](https://godoc.org/github.com/samber/do) (杂项 / 依赖注入)
- awesome-go - do - A dependency injection framework based on Generics. (Miscellaneous / Dependency Injection)
- awesome-go - do - A dependency injection framework based on Generics. (Miscellaneous / Dependency Injection)
- awesome-go - do - A dependency injection framework based on Generics. Stars:`2.3K`. (Miscellaneous / Dependency Injection)
README
# do - Dependency Injection
[](https://github.com/samber/do/releases)

[](https://pkg.go.dev/github.com/samber/do)

[](https://goreportcard.com/report/github.com/samber/do)
[](https://codecov.io/gh/samber/do)
[](./LICENSE)
**⚙️ A dependency injection toolkit based on Go 1.18+ Generics.**
This library implements the Dependency Injection design pattern. It may replace the fantastic `uber/dig` package. `samber/do` uses Go 1.18+ generics and therefore offers a type‑safe API.

**See also:**
- [samber/ro](https://github.com/samber/ro): Reactive Programming for Go: declarative and composable API for event-driven applications
- [samber/lo](https://github.com/samber/lo): A Lodash-style Go library based on Go 1.18+ Generics
- [samber/mo](https://github.com/samber/mo): Monads based on Go 1.18+ Generics (Option, Result, Either...)
- [samber/cc-skills-golang](https://github.com/samber/cc-skills-golang): AI Agent Skills for Golang
----
----
**Why this name?**
I love the **short name** for such a utility library. This name is the sum of `DI` and `Go` and no Go package uses this name.
## 💡 Features
- **📒 Service registration**
- Register by type
- Register by name
- Register multiple services from a package at once
- **🪃 Service invocation**
- Eager loading
- Lazy loading
- Transient loading
- Tag-based invocation
- Circular dependency detection
- **🧙♂️ Service aliasing**
- Implicit (provide struct, invoke interface)
- Explicit (provide struct, bind interface, invoke interface)
- **🔁 Service lifecycle**
- Health check
- Graceful unload (shutdown)
- Dependency-aware parallel shutdown
- Lifecycle hooks
- **📦 Scope (a.k.a module) tree**
- Visibility control
- Dependency grouping
- **📤 Container**
- Dependency graph resolution and visualization
- Default container
- Container cloning
- Service override
- **🧪 Debugging & introspection**
- Explain APIs: scope tree and service dependencies
- Web UI & HTTP middleware (std, Gin, Fiber, Echo, Chi)
- **🌈 Lightweight, no dependencies**
- **🔅 No code generation**
- **😷 Type‑safe API**
## 🚀 Install
```sh
# v2 (latest)
go get github.com/samber/do/v2@latest
# v1
go get github.com/samber/do@v1.6.0
# AI Agent Skill
npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-do
```
This library is v2 and follows SemVer strictly.
No breaking changes will be made to exported APIs before v3.0.0.
This library has no dependencies except the Go std lib.
### 🔥 Migration from v1 to v2
[Documentation here](https://do.samber.dev/docs/upgrading/from-v1-x-to-v2)
## 🤠 Documentation
- [GoDoc: https://godoc.org/github.com/samber/do/v2](https://godoc.org/github.com/samber/do/v2)
- [Documentation](https://do.samber.dev/docs/getting-started)
- [Examples](https://github.com/samber/do/tree/master/examples)
- [Project templates](https://do.samber.dev/examples)
## 🎬 Project boilerplate
- [do-template-api](https://github.com/samber/do-template-api)
- [do-template-worker](https://github.com/samber/do-template-worker)
- [do-template-cli](https://github.com/samber/do-template-cli)
## 🤝 Contributing
- Ping me on Twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))
- Fork the [project](https://github.com/samber/do)
- Fix [open issues](https://github.com/samber/do/issues) or request new features
Don't hesitate ;)
```bash
# Install some dev dependencies
make tools
# Run tests
make test
# or
make watch-test
```
## 👤 Contributors

## 💫 Show your support
Give a ⭐️ if this project helped you!
[](https://github.com/sponsors/samber)
## 📝 License
Copyright © 2022 [Samuel Berthe](https://github.com/samber).
This project is [MIT](./LICENSE) licensed.