Wire

Compile-time dependency injection for Go that generates plain, debuggable initialization code with zero runtime reflection.

Tool
Go
vv0.7.0
14,406stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
46/100Fair
Development Activity0
Maintenance20
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture80
Code Quality75
Innovation70
Learning Curve80

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 wire CLI (installed via go install github.com/google/wire/cmd/wire@latest) with gen, diff, show, and check subcommands
  • A wire package of marker functions (NewSet, Build, Bind, Value, InterfaceValue, Struct, FieldsOf) used to declare provider sets in injector templates
  • Static analysis over Go’s go/packages and go/types APIs 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 NewApp constructor 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

Go
60%
Apache 2.0

Apache Answer

Community

15,658

Open-source Q&A platform for communities, help centers, and knowledge bases with AI assistant and plugin extensibility

View details
84
Repo Health
78
Technical
68
Dependency
Built with
Go60%
TypeScript36%
Updated 2 days ago
Go
55%
Apache 2.0

Authgear

Authentication

2,014

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.

View details
88
Repo Health
81
Technical
69
Dependency
Built with
Go55%
HTML25%
TypeScript17%
Updated 4 days ago
TypeScript
49%
AGPL 3.0

Grafana

Monitoring · Analytics

76,498

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
65
Dependency
Built with
TypeScript49%
Go45%
Updated today
Go
61%
Apache 2.0

Harness Open Source

Developer Tools · Devops · Code Editors

38,169

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
89
Repo Health
79
Technical
64
Dependency
Built with
Go61%
TypeScript34%
Updated 2 days ago
Go
81%
GPL 3.0

Navidrome

File Storage

23,217

Run your own personal Spotify — stream your entire music collection from any device, anywhere, forever.

View details
91
Repo Health
81
Technical
70
Dependency
Built with
Go81%
JavaScript15%
Updated today
Go
78%
Apache 2.0

OpenMeter

Invoicing Finance · Developer Tools

2,236

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.

View details
86
Repo Health
81
Technical
66
Dependency
Built with
Go78%
TypeScript17%
Updated 2 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search