MCPcopy
hub / github.com/samber/do

github.com/samber/do @v2.0.0 sqlite

repository ↗ · DeepWiki ↗ · release v2.0.0 ↗
423 symbols 897 edges 31 files 220 documented · 52%
README

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 fantastic uber/dig package. samber/do uses Go 1.18+ generics and therefore offers a type‑safe API.

image

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.

💡 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

# 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.

🔥 Migration from v1 to v2

Documentation here

🤠 Documentation

🤝 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.

Extension points exported contracts — how you extend this code

Healthchecker (Interface)
Healthchecker is an interface that services can implement to provide health checking capabilities. Services implementing [3 …
di_lifecycle.go
Injector (Interface)
Injector is the main interface for dependency injection containers. It provides methods for service registration, resolu [3 …
injector.go
Provider (FuncType)
Provider is a function type that creates and returns a service instance of type T. This is the core abstraction for serv
di.go
HealthcheckerWithContext (Interface)
HealthcheckerWithContext is an interface that services can implement to provide health checking capabilities with contex [3 …
di_lifecycle.go
Shutdowner (Interface)
Shutdowner is an interface that services can implement to provide graceful shutdown capabilities. Services implementing [3 …
di_lifecycle.go
ShutdownerWithError (Interface)
ShutdownerWithError is an interface that services can implement to provide graceful shutdown capabilities with error rep [3 …
di_lifecycle.go
ShutdownerWithContext (Interface)
ShutdownerWithContext is an interface that services can implement to provide graceful shutdown capabilities with context [3 …
di_lifecycle.go

Core symbols most depended-on inside this repo

ID
called by 20
injector.go
RootScope
called by 16
injector.go
mAp
called by 13
utils.go
Name
called by 11
injector.go
getInjectorOrDefault
called by 11
injector.go
serviceGetRec
called by 10
injector.go
Shutdown
called by 9
injector.go
newServiceDescription
called by 9
dag.go

Shape

Method 235
Function 144
Interface 22
Struct 19
TypeAlias 2
FuncType 1

Languages

Go100%

Modules by API surface

service.go58 symbols
root_scope.go39 symbols
di.go37 symbols
injector.go35 symbols
scope.go32 symbols
virtual_scope.go30 symbols
utils.go24 symbols
di_lifecycle.go24 symbols
di_explain.go19 symbols
service_lazy.go16 symbols
service_transient.go14 symbols
service_eager.go14 symbols

Dependencies from manifests, versioned

github.com/andybalholm/brotliv1.0.5 · 1×
github.com/bytedance/sonicv1.9.1 · 1×
github.com/chenzhuoyu/base64xv0.0.0-2022111506244 · 1×
github.com/gin-contrib/ssev0.1.0 · 1×
github.com/go-playground/localesv0.14.1 · 1×
github.com/go-playground/universal-translatorv0.18.1 · 1×

Datastores touched

dbDatabase · 1 repos

For agents

$ claude mcp add do \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact