godi Documentation
“Dependency injection is not about the tools, it’s about the design. But having great tools makes great design achievable.”
godi brings modern, type-safe dependency injection to Go, making your applications more maintainable, testable, and scalable. Built on Uber’s dig with a Microsoft-inspired API, it provides the power you need with the simplicity you want.
Why godi?
Never touch constructors again when adding dependencies
Automatic lifecycle management for resources
Request scoping for web applications
Zero boilerplate dependency wiring
Type-safe with compile-time verification
Testable by design
Quick Example
// Define your services
services := godi.NewServiceCollection()
services.AddSingleton(NewLogger)
services.AddScoped(NewDatabase)
services.AddTransient(NewEmailService)
// Build the container
provider, _ := services.BuildServiceProvider()
defer provider.Close()
// Resolve and use
logger, _ := godi.Resolve[Logger](provider)
logger.Log("Application started!")