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?

  1. Never touch constructors again when adding dependencies

  2. Automatic lifecycle management for resources

  3. Request scoping for web applications

  4. Zero boilerplate dependency wiring

  5. Type-safe with compile-time verification

  6. 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!")