godi

A small reflection-based dependency injection container for Go — register by name, inject into tagged struct fields.

Godependency injection · reflection · librarylanguages & frameworkssource on github

Why

Centralized dependency registration for modular, testable Go applications, in a single file.

How

A map of names to instances; Resolve uses reflect to fill exported fields tagged inject:"Name", with ResolveAll and ListDependencies alongside. Missing dependencies are returned as errors.

It’s the runtime, string-keyed take on the problem — the approach goboot later replaced with compile-time resolution.

type MyStruct struct { Service *MyService `inject:"MyService"` }
err := container.Resolve(&MyStruct{})
$ git clone https://github.com/zombocoder/godi
← all projects