Dependency Injection

27 projects

Dependency injection in Go usually means passing dependencies as constructor arguments and wiring them together in main. The libraries here automate that wiring for larger applications, building a graph of constructors and calling them in the right order. They differ in when wiring happens: at runtime with reflection, at runtime with generics, or at build time through code generation.

Uber's fx is the most used framework; it builds on uber-go/dig, a reflection-based container, and adds application lifecycle hooks for starting and stopping servers and modules for grouping providers. samber/do takes a generics-based approach with explicit registration and invocation, health checks and graceful shutdown. Smaller containers include GoLobby's container, goioc/di inspired by Spring, dingo inspired by Guice, godi with scoped lifetimes in the style of .NET, and nject. Go-Spring is archived. Several entries are small personal projects, so check activity before adopting one.

For small and medium services, manual wiring in main is clear, fast and easy to debug, and the compiler checks it. Consider fx when many teams contribute modules to one large application and lifecycle management matters. Consider samber/do if you want a container but prefer generics over reflection. Reflection-based errors appear at startup rather than compile time, so test application startup in CI.

fxby uber-go

A dependency injection based application framework for Go (built on top of dig).

go.uber.org/fxGo 1.24+ 6 dependenciesv1.24.0updated 10mo ago

7.7k

digby uber-go

A reflection based dependency injection toolkit for Go.

go.uber.org/digGo 1.20+ 1 dependencyv1.19.0updated 1y ago

4.5k

doby samber

A dependency injection framework based on Generics.

github.com/samber/do/v2Go 1.18+ 3 dependenciesv2.1.0updated 1d ago

2.8k

GoLobby/Containerby golobby

GoLobby Container is a lightweight yet powerful IoC dependency injection container for the Go programming language.

github.com/golobby/container/v3Go 1.17+ 1 dependencyv3.3.2updated 1y ago

610

goioc/diby goioc

Spring-inspired Dependency Injection Container.

github.com/goioc/diGo 1.26+ 2 dependenciesv2.1.0updated 3d ago

379

kodby go-kod

A generics based dependency injection framework for Go.

github.com/go-kod/kodGo 1.27+ 18 dependenciesv0.19.0updated 2mo ago

199

dingoby i-love-flamingo

A dependency injection toolkit for Go, based on Guice.

flamingo.me/dingoGo 1.26+ 2 dependenciesv0.4.1updated 3d ago

189

gontainerby NVIDIA

A dependency injection service container for Go projects.

github.com/NVIDIA/gontainer/v2Go 1.21+ No dependencies v2.5.1updated 3mo ago

157

Go-Spring

A high-performance Go framework inspired by Spring Boot, offering DI, auto-configuration, and lifecycle management while maintaining Go's simplicity and efficiency.

v1.3.0archived

84

godiby junioryono

Microsoft-style dependency injection for Go with scoped lifetimes and generics.

github.com/junioryono/godi/v6Go 1.26+ 2 dependenciesv6.1.0updated 4d ago

78

aliceby magic003

Additive dependency injection container for Golang.

v0.1updated 9y ago

51

wireby Fs02

Strict Runtime Dependency Injection for Golang.

github.com/Fs02/wire3 dependenciesv1.0.2updated 5y ago

40

boot-go

Component-based development with dependency injection using reflections for Go developers.

github.com/boot-go/bootGo 1.18+ No dependencies updated 2y ago

37

parsleyby matzefriedrich

A flexible and modular reflection-based DI library with advanced features like scoped contexts and proxy generation, designed for large-scale Go applications.

github.com/matzefriedrich/parsleyGo 1.27+ 5 dependenciesv1.7.2updated today

37

linkerby logrange

A reflection based dependency injection and inversion of control library with components lifecycle support.

github.com/logrange/linkerGo 1.13+ No dependencies updated 1y ago

35

njectby muir

A type safe, reflective framework for libraries, tests, http endpoints, and service startup.

github.com/muir/nject/v2Go 1.23+ 2 dependenciesv2.1.0updated 24d ago

33

componego

A dependency injection framework based on components, allowing dynamic dependency replacement without duplicating code in tests.

github.com/componego/componegoGo 1.22+ No dependencies v0.2.0updated 2y ago

29

oreby firasdarwish

Lightweight, generic & simple dependency injection (DI) container.

github.com/firasdarwish/oreGo 1.22+ 1 dependencyv0.7.0updated 8mo ago

28

gocontainerby vardius

Simple Dependency Injection Container.

github.com/vardius/gocontainer/v2Go 1.26+ No dependencies v2.0.0updated 3d ago

21

gontainer/gontainerby gontainer

A YAML-based Dependency Injection container for GO. It supports dependencies' scopes, and auto-detection of circular dependencies. Gontainer is concurrent-safe.

github.com/gontainer/gontainerGo 1.21+ 8 dependenciesv0.8.3updated 2y ago

17

floatdrop/diby floatdrop

Dependency injection container built on generic methods, with child scopes, lifecycle hooks and graph validation before anything is built.

golang.yandex/diGo 1.27+ No dependencies v0.20.0updated 23d ago

15

autowireby tiendc

Dependency injection using Generics and reflection.

v0.5.0archived

12

kinitby go-kata

Customizable dependency injection container with the global mode, cascade initialization and panic-safe finalization.

github.com/go-kata/kinitGo 1.14+ 2 dependenciesupdated 5y ago

10

HnH/diby HnH

DI container library that is focused on clean API and flexibility.

github.com/HnH/diGo 1.18+ 1 dependencyv1.3.3updated 11mo ago

9

go-beans

Spring-inspired dependency injection and application lifecycle framework for Go.

github.com/go-beans/goGo 1.26+ 4 dependenciesv1.0.85updated 10d ago

2

yamaby livetribe

Compile-time dependency injection and lifecycle framework that generates start, quiesce, and stop code for Google Wire graphs.

l7e.io/yamaGo 1.26+ 8 dependenciesv0.5.1updated 1d ago

0
c

cosban/di

A code generation based dependency injection wiring tool.

gitlab.com

Esc

Type to search every entry. ↑↓ to move, Enter to open.