Skip to content
/ do Public

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

License

Notifications You must be signed in to change notification settings

samber/do

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

do - Dependency Injection

tag Go Version GoDoc Build Status Go report Coverage License

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

This library implements the Dependency Injection design pattern. It may replace the uber/dig fantastic package. samber/do uses Go 1.18+ generics instead of reflection and therefore offers a typesafe API.

See also:

  • 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...)

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.

🔥 Migration from v1 to v2

Documentation here

💡 Features

  • 📒 Service registration
    • By type inference
    • By name
  • 🪃 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)
    • Lifecycle hooks
  • 📦 Scope (a.k.a module) tree
    • Visibility control
    • Dependency grouping
  • 📤 Container
    • Dependency graph resolution and visualization
    • Default container
    • Container cloning
    • Service override
  • 🌈 Lightweight, no dependencies
  • 🔅 No code generation
  • 😷 Typesafe API

🚀 Install

# v2 (latest)
go get github.com/samber/do@v2

# v1
go get github.com/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.

🤠 Documentation

🛩 Benchmark

// @TODO

🤝 Contributing

Don't hesitate ;)

# Install some dev dependencies
make tools

# Run tests
make test
# or
make watch-test

👤 Contributors

Contributors

💫 Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

📝 License

Copyright © 2022 Samuel Berthe.

This project is MIT licensed.