do - Dependency Injection is a lightweight dependency injection toolkit for Go that implements the DI pattern using the language’s generics system to provide strong type safety and minimal runtime overhead. The library offers a service container that allows developers to register, resolve, and manage application dependencies in a structured and maintainable way. It supports multiple service lifecycles such as eager, lazy, and transient loading, along with circular dependency detection and interface binding. The toolkit is designed to improve modularity, testability, and scalability in Go applications by reducing tight coupling between components. It also includes lifecycle management features like health checks and graceful shutdown handling, making it suitable for production services and microservices. Overall, samber/do delivers a modern, generics-powered alternative to traditional reflection-based DI frameworks in Go.
Features
- Type-safe dependency injection container
- Service registration by type or name
- Lazy eager and transient lifecycles
- Circular dependency detection
- Health check and graceful shutdown
- Dependency graph resolution