Uber fx (Go)
Application framework for Go providing dependency injection with lifecycle management. Unlike Wire (compile-time, no lifecycle), fx runs at application startup using reflection-based DI — components declare dependencies via function parameters, fx resolves the graph at startup, and manages Start/Stop lifecycle hooks for graceful shutdown. Used internally at Uber for microservices. Ideal for long-running Go agent services needing structured startup/shutdown.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Local service framework — no network calls. Reflection-based DI doesn't introduce security vulnerabilities. Application security depends on provided components.
⚡ Reliability
Best When
You're building production Go agent services needing structured startup, graceful shutdown, and runtime dependency injection — fx's lifecycle hooks prevent common 'service didn't shut down cleanly' bugs.
Avoid When
You want compile-time DI safety without reflection or need maximum startup performance — Wire generates plain Go code with no runtime overhead.
Use Cases
- • Build Go agent service with structured startup — fx resolves all dependencies in correct order and calls OnStart hooks (DB connections, listeners, background workers)
- • Implement graceful shutdown for agent services — register OnStop hooks for clean connection draining without manual lifecycle management
- • Modularize large Go agent applications into fx modules — group related providers into modules that can be included/excluded as needed
- • Use fx for test isolation — fx.Options composition allows swapping real providers with test fakes in integration tests
- • Add health checks and observability to agent services via fx lifecycle hooks that register/deregister health endpoints on startup/shutdown
Not For
- • Compile-time DI with zero runtime overhead — use Wire for generated, zero-reflection DI
- • Simple applications with few dependencies — fx's reflection-based approach adds startup overhead and complexity not needed for small services
- • Teams new to Go DI patterns — fx's Provide/Invoke/Supply API requires understanding DI concepts before the framework becomes productive
Interface
Authentication
Library — no external auth. Application DI framework for local service composition.
Pricing
MIT-licensed open source from Uber.
Agent Metadata
Known Gotchas
- ⚠ fx.Provide() uses reflection — type errors in providers surface at runtime during app.New(), not at compile time; thorough testing of DI configuration is essential
- ⚠ fx.Invoke() runs immediately at startup for side-effect functions (registering routes, starting goroutines) — errors in Invoke functions abort startup with clear error messages
- ⚠ Circular dependencies cause a panic at startup with a cycle description — redesign the dependency graph; fx cannot resolve cycles even with lazy initialization
- ⚠ fx.Lifecycle.Append() OnStop hooks run in reverse registration order — ensure cleanup order matches initialization order by registering in dependency order
- ⚠ Using fx in tests requires fx.Options composition — create test modules with fake/mock providers and compose them with real modules for integration testing
- ⚠ Large dependency graphs with many providers can make startup errors hard to trace — use fx.WithLogger for verbose dependency resolution logging during development
Alternatives
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for Uber fx (Go).
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-07.