do
A dependency injection framework based on Generics
About do
do - Dependency Injection
โ๏ธ 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: Reactive Programming for Go: declarative and composable API for event-driven applications
- samber/lo: A Lodash-style Go library based on Go 1.18+ Generics
- samber/mo: Monads based on Go 1.18+ Generics (Option, Result, Either...)
- 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
# 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-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
๐ฌ Project boilerplate
๐ค Contributing
- Ping me on Twitter @samuelberthe (DMs, mentions, whatever :))
- Fork the project
- Fix open issues or request new features
Don't hesitate ;)
# 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!
๐ License
Copyright ยฉ 2022 Samuel Berthe.
This project is MIT licensed.
Frequently Asked Questions
What is do?
do is a Miscellaneous library for the Go programming language. A dependency injection framework based on Generics
How do I install do?
Install do with the Go module system using `go get samber/do`. Check the repository for the current installation instructions.
What category does do belong to?
do is listed under Miscellaneous, specifically Dependency Injection.