Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

do

> 开发工具
Open source

⚙️ A dependency injection toolkit based on Go 1.18+ Generics.

2.8K stars0 likes2 views
WebsiteGitHub

About

⚙️ A dependency injection toolkit based on Go 1.18+ Generics.

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

bash
# 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 here

Documentation

  • GoDoc: https://godoc.org/github.com/samber/do/v2
  • Documentation
  • Examples
  • Project templates

Project boilerplate

  • do-template-api
  • do-template-worker
  • do-template-cli

Contributing

  • Ping me on Twitter @samuelberthe (DMs, mentions, whatever :))
  • Fork the project
  • Fix open 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!

License

Copyright © 2022 Samuel Berthe.

This project is MIT licensed.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gocontainerdependencydependency-graphdi

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具