Compile-time dependency injection for Go - fast, explicit, and reflection-free.
wire generates plain Go code to wire your application together.
No runtime container, no reflection, no hidden magic - just fast, explicit initialization.
Note
This is a maintained fork of google/wire.
The original project is no longer actively maintained.
This fork preserves Wire’s API and behavior while focusing on:
- 8-10x+ Faster compile times
- Improved generator determinism
- Better documentation and developer ergonomics (wire watch etc.)
Existing Wire codebases should work without modification.
Wire is a code generation tool that automates connecting components using dependency injection. Dependencies between components are represented in Wire as function parameters, encouraging explicit initialization instead of global variables. Because Wire operates without runtime state or reflection, code written to be used with Wire is useful even for hand-written initialization.
For an overview, see the introductory blog post.
go install github.com/goforj/wire/cmd/wire@latestEnsure $GOPATH/bin is in your $PATH.
Wire remains compatible with codebases that import github.com/google/wire.
The generator emits a //go:generate directive pointing at this fork so
go generate consistently uses the maintained toolchain.
To keep existing imports unchanged:
go mod edit -replace=github.com/google/wire=github.com/goforj/wire@latestWire is a compile-time dependency injection tool. Instead of building a runtime container, Wire generates ordinary Go code that explicitly initializes your application.
There are only two concepts to learn:
A provider is a normal Go function that produces a value (and optionally an error).
func NewDB(cfg Config) (*sql.DB, error) {
// ...
}Dependencies are expressed as function parameters - no globals, no hidden state.
An injector is a stub function whose body calls wire.Build(...).
Wire replaces this stub with generated code that calls providers in dependency
order.
func InitializeApp(cfg Config) (*App, error) {
wire.Build(AppSet)
return nil, nil
}The generated output is plain Go - readable, debuggable, and fast.
// providers.go
type Message string
func ProvideMessage() Message {
return "hello wire"
}
type Greeter struct {
Msg Message
}
func NewGreeter(msg Message) *Greeter {
return &Greeter{Msg: msg}
}
var GreeterSet = wire.NewSet(
ProvideMessage,
NewGreeter,
)// wire.go
//go:build wireinject
func InitializeGreeter() *Greeter {
wire.Build(GreeterSet)
return nil
}Generate the injector:
wireWire produces wire_gen.go containing explicit initialization code with no
runtime dependency on Wire.
Run the default command (alias for wire gen) or specify packages:
wire
wire gen ./...Wire includes a native watcher that re-runs generation on Go file changes:
wire watch
wire watch ./...Detects the package root automatically and uses native filesystem notifications when available (with a polling fallback).
Wire favors explicitness and long-term maintainability:
- Prefer small provider sets, especially in libraries
- Avoid injecting common types like
string; define distinct types instead - Treat provider sets as public APIs with compatibility guarantees
- Use struct providers and interface bindings to keep graphs readable
For detailed guidance, see Best Practices.
If you're new to Wire, we recommend reading in this order:
- Tutorial - A guided introduction with a complete working example
- User Guide - Full reference for providers, injectors, bindings, and advanced patterns
- Best Practices - Design guidance for large codebases and libraries
- FAQ - Design rationale and common questions
Wire is designed for medium-to-large Go applications with non-trivial initialization logic.
For small programs with only a handful of dependencies, hand-written initialization is often simpler and clearer.
This fork tracks the original Wire feature set while prioritizing performance, determinism, and documentation. Compatibility with existing Wire codebases is a core goal.
For questions and discussion, use GitHub Discussions.
This project follows the Go Code of Conduct.
