A type-safe, performance-focused dependency injection framework for Go, built on top of context.Context.
- Type-Safe: No
interface{}type assertions in your business logic. - High Performance: No reflection penalty at runtime; retrieval is a simple map lookup.
- Context-Based: Seamlessly integrates with standard Go middleware and request flows.
- Robust: Built-in circular dependency detection and deterministic injection order.
- Reliable: 100% test coverage.
// 1. Define a module token
var ModuleDB = module.New[DB]()
// 2. Register a provider
repo := module.NewRepo()
repo.Add(ModuleDB.ProvideValue(&db{target: "local.db"}))
// 3. Inject and use
ctx, _ := repo.InjectTo(context.Background())
database := ModuleDB.Value(ctx) // Returns DB type directlyFor more detailed usage, including dependency chains and scoped overrides, see the Examples or .