Wire
Compile-time dependency injection for Go that generates plain, debuggable initialization code with zero runtime reflection.
Repository Health
Technical Analysis
Wire is a code generation tool from Google that automates dependency injection in Go programs. Instead of wiring components together with a runtime DI container or global variables, developers write ordinary provider functions and injector templates; the wire CLI analyzes the call graph at compile time and emits a plain Go source file that performs the initialization explicitly.
Because the generated code is just Go — no reflection, no runtime container, no hidden magic — it reads like hand-written wiring, is easy to step through in a debugger, and adds no runtime overhead. Wire is best suited to Go services with non-trivial construction graphs (databases, HTTP clients, config, loggers) where manual wiring becomes repetitive and error-prone. The project has been in maintenance-only mode since 2023, with the maintainers now directing new feature work to community forks.
What You Get
- The
wireCLI (installed viago install github.com/google/wire/cmd/wire@latest) withgen,diff,show, andchecksubcommands - A
wirepackage of marker functions (NewSet,Build,Bind,Value,InterfaceValue,Struct,FieldsOf) used to declare provider sets in injector templates - Static analysis over Go’s
go/packagesandgo/typesAPIs that builds a dependency graph from provider function signatures and detects cycles or missing providers at generation time - Support for provider sets that can be composed across packages, interface bindings, cleanup functions, and error-returning providers with automatic cleanup-on-error
- A full tutorial, user guide, FAQ, and best-practices doc under
docs/and_tutorial/
Common Use Cases
- Wiring together a Go service’s database connections, HTTP clients, config, and loggers into a single
NewAppconstructor without hand-written boilerplate - Swapping implementations (e.g. a mock vs a real store) between test and production builds by changing which provider set an injector references
- Keeping large constructor graphs maintainable in modular monoliths by composing provider sets per package instead of one giant
main.go - Generating explicit, reviewable initialization code for teams that want to avoid runtime reflection-based DI frameworks entirely
Under The Hood
Architecture
Wire’s pipeline is a straightforward three-stage compiler: internal/wire/parse.go loads the target package with go/packages and go/types to locate injector function templates and their wire.Build calls; internal/wire/analyze.go walks the referenced provider sets to build a directed dependency graph of provider inputs/outputs, resolving bindings and detecting cycles or unsatisfied types before generation; internal/wire/copyast.go and wire.go then synthesize the final injector body by topologically ordering providers and copying/rewriting the needed AST fragments into a single generated file. cmd/wire/main.go is a thin CLI shell around this pipeline built on google/subcommands, exposing gen, diff, show, and check as separate commands. The top-level wire package that users import (wire.go) contains no real logic at all — NewSet, Build, Bind, etc. are inert marker functions whose only job is to type-check in source; the actual behavior lives entirely in the internal/wire analysis package, which is a clean and deliberate separation between the public directive surface and the private compiler internals.
Tech Stack
Wire is a pure Go 1.19+ tool with no runtime dependencies beyond the standard library and golang.org/x/tools (go/packages, go/ast, go/types) for static analysis, plus golang.org/x/mod and golang.org/x/sync as indirect dependencies. The CLI layer uses google/subcommands for command dispatch, and testing relies on google/go-cmp for structural diffing and pmezard/go-difflib for generated-output diffs. There is no web framework, database layer, or deployment target — it ships as a single static binary invoked via go generate or directly from the command line.
Code Quality
The test suite in internal/wire/wire_test.go is a large golden-file harness that compiles dozens of named scenarios under internal/wire/testdata/ (covering cycles, interface bindings, struct field injection, cleanup functions, build tags, and more) and diffs generated output against expected results using go-cmp. Error handling is explicit throughout — the analysis stage returns structured errors (internal/wire/errors.go) rather than panicking, and the CLI surfaces them with source-position context. CI (GitHub Actions) runs the test suite across Ubuntu, macOS, and Windows with code coverage reported to Codecov. No dedicated linter config (e.g. golangci-lint) was found in the repo; the project relies on go vet and standard gofmt conventions.
What Makes It Unique Wire’s defining choice is doing dependency injection entirely at compile time via code generation rather than at runtime via reflection or a container object graph — the generated file is ordinary, readable Go that a developer could have written by hand, so there is no performance cost, no reflection-based magic, and stepping through initialization in a debugger works exactly as it would for manually wired code. This trades some flexibility (the object graph is fixed at generation time, not reconfigurable at runtime) for transparency and zero runtime overhead, a tradeoff distinct from most other DI approaches in the Go ecosystem.
Used by 6 apps in this directory
Apache Answer
Community
Open-source Q&A platform for communities, help centers, and knowledge bases with AI assistant and plugin extensibility
Authgear
Authentication
Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.
Grafana
Monitoring · Analytics
The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.
Harness Open Source
Developer Tools · Devops · Code Editors
A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.
Navidrome
File Storage
Run your own personal Spotify — stream your entire music collection from any device, anywhere, forever.
OpenMeter
Invoicing Finance · Developer Tools
Open-source metering and billing engine for AI, agentic, and DevTool monetization — ingest usage events in real time and turn them into accurate invoices automatically.