For Go 服务依赖注入工具包, the strongest matches are google/wire (Wire is a compile-time dependency injection framework for Go), samber/do (samber/do is a type-safe dependency injection framework for Go) and uber-go/fx (Fx is a Go dependency injection framework that provides). uber-go/dig and golobby/container round out the shortlist. Each is ranked by relevance to your query, popularity and recent activity.
用于在 Go 应用中管理对象依赖和服务的库和框架。
Wire is a compile-time dependency injection framework for Go that generates code to wire application components together. It analyzes function signatures at compile time to build an explicit initialization graph, removing the need for runtime reflection or manual wiring code. The framework operates as a Go code generator and static analysis tool, transforming annotated source code into generated wire files that compile alongside the original project. It connects dependencies by matching function parameters and return types, producing a directed acyclic graph of component dependencies that is
Wire is a compile-time dependency injection framework for Go that generates code to wire components together via constructor injection and automatic resolution, fitting your need for decoupled dependencies, though it may not explicitly cover scope management or lifecycle hooks.
This project is a type-safe dependency injection framework for Go that manages application lifecycles and injects dependencies into structures using reflection and metadata tags. It functions as a service lifecycle manager and an interface binding library to decouple service consumption from concrete implementations. The framework utilizes a hierarchical service container, organizing services into a tree of nested scopes where child containers inherit dependencies from their ancestors. It includes a dependency graph visualizer for inspecting relationships and invocation chains, as well as a s
samber/do is a type-safe dependency injection framework for Go that supports constructor injection, hierarchical scopes, and lifecycle management (start/stop hooks), but it uses reflection rather than compile-time code generation, which matches the core category while missing the requested compile-time injection feature.
Fx is a dependency injection framework and application lifecycle manager for Go. It functions as a component model container that automates the instantiation and connection of components by analyzing constructor parameters and return values to resolve complex dependency graphs. The framework distinguishes itself through module-based component bundling, which encapsulates related constructors into reusable units to manage visibility and logic. It provides advanced resolution capabilities, including mapping concrete types to interfaces for decoupling, resolving dependency ambiguities via unique
Fx is a Go dependency injection framework that provides constructor injection, automatic dependency resolution, and lifecycle hooks, though it uses runtime reflection rather than compile-time code generation — a solid fit for decoupled dependencies in Go services.
dig is a reflection-based dependency injection framework and object graph resolver for Go. It functions as a container that automatically satisfies type dependencies and manages the instantiation of complex networks of objects during application startup. The project utilizes a directed acyclic graph to determine the necessary sequence for object instantiation and employs interface-driven provider mapping to decouple concrete implementations from their satisfied interfaces. It resolves the object hierarchy through reflection-based type resolution and single-pass component wiring to ensure all
uber-go/dig is a reflection-based dependency injection toolkit for Go that provides constructor injection and automatic resolution, fitting the core request for a DI framework, though it lacks built-in scope management, lifecycle hooks, and compile-time generation.
A lightweight yet powerful IoC dependency injection container for the Go programming language
golobby/container is a lightweight IoC dependency injection container for Go that supports constructor injection and automatic resolution, squarely fitting the search for a Go dependency injection framework for decoupled services, though it may lack lifecycle hooks or compile-time code generation.
🛠 A full-featured dependency injection container for go programming language.
Goava/di is a full-featured dependency injection container for Go, directly matching the need for decoupling dependencies in services, though details on specific features like lifecycle hooks or compile-time injection are not confirmed.
Inject is a dependency injection library for Go that manages object lifecycles and wires application components by automating the provision of dependencies. It functions as a reflection-based container that maps specific values to their corresponding types, enabling the automatic retrieval and injection of objects into application logic. The library distinguishes itself through its ability to perform automatic function invocation, where it inspects function signatures at runtime to resolve and provide required arguments from a central registry. It also supports struct field injection, which p
codegangsta/inject is a dependency injection library for Go that provides the core capability of injecting dependencies to decouple services, fitting the requested category, though its simple description does not indicate support for advanced features like scope management or lifecycle hooks.