# dig

A Go dependency-injection library that generates plain Go code at compile time, combining a minimal Fx-style API with Wire-style code generation so there is no runtime reflection or extra runtime dependency.

dig is a compile-time, code-generation dependency-injection library for Go, positioned between Uber's Fx, which offers an elegant API but relies on runtime reflection and can panic on dependency errors, and Google's Wire, which is reflection-free but has a verbose, counter-intuitive API. dig combines a minimal API of Build, Provide, Supply, Invoke and Module with Wire-style generation, so the dependency graph is resolved and checked when code is generated rather than at runtime.

Generated code is plain Go with no third-party runtime dependency, and the generator enforces closure-capture safety so inline closures cannot accidentally capture local variables, while also supporting generics and multiple instances of the same type distinguished by parameter names. The project is unrelated to Uber's own runtime-reflection container of a similar name, and ships a set of AI-assistant prompts documenting its API, troubleshooting and migration from Wire or Fx.

Website: https://github.com/shanjunmei/dig
