golang-uber-fx
Golang application framework using uber-go/fx — fx.New, fx.Provide, fx.Invoke, fx.Module, fx.Lifecycle hooks, fx.Annotate (name/group/As), fx.Decorate, fx.Supply, fx.Replace, fx.WithLogger, and signal-aware Run(). Apply when using or adopting uber-go/fx, when the codebase imports `go.uber.org/fx`, or when wiring services with fx.New. For raw DI without lifecycle, see `samber/cc-skills-golang@golang-uber-dig` skill.
Security Assessment
About golang-uber-fx
The golang-uber-fx skill provides expertise in building Go applications using uber-go/fx, a reflection-based dependency injection framework with integrated lifecycle management. This skill addresses the challenge of wiring complex service graphs in long-running Go applications by combining DI container capabilities with structured startup/shutdown sequences, signal handling, and modular composition. It's designed for architects and developers who need to move beyond manual initialization and ad-hoc shutdown logic toward a framework that manages boot order, graceful termination, and dependency resolution automatically.
The skill covers core fx primitives including fx.New for application creation, fx.Provide for constructor registration, fx.Invoke for execution triggers, and fx.Lifecycle for managing OnStart/OnStop hooks. It extends to advanced patterns like fx.Module for scoped composition, fx.Annotate for named values and value groups, fx.Decorate for wrapping dependencies, and fx.Supply/fx.Replace for runtime value injection. The framework includes a signal-aware Run() method that blocks until SIGINT/SIGTERM, built-in structured logging via fx.WithLogger, and configurable startup/shutdown timeouts. Built on top of uber-go/dig, fx inherits all DI container features while adding the application lifecycle layer that dig lacks.
This skill is ideal for teams building HTTP servers, background workers, daemons, or any long-running Go service where clean startup sequencing and graceful shutdown are critical. It's particularly valuable for microservices architectures where multiple components need coordinated initialization, for replacing fragile init() patterns with explicit lifecycle hooks, and for large codebases where fx.Module enables better separation of concerns. The skill applies when adopting uber-go/fx in new projects, migrating existing services to fx-based wiring, or troubleshooting dependency resolution in fx applications.
FAQ
When should I use fx instead of raw uber-go/dig?
Choose fx for long-running services like HTTP servers, workers, or daemons where lifecycle management and signal handling are essential. Use raw dig for CLI tools, libraries that expose containers to callers, or when embedding DI into applications that already manage their own lifecycle.
What happens if a constructor or lifecycle hook times out?
fx enforces a 15-second default timeout for both startup (fx.StartTimeout) and shutdown (fx.StopTimeout). If any OnStart hook or constructor invocation exceeds this limit, the application fails to start. If OnStop hooks timeout during shutdown, fx logs the timeout and continues. You can override these defaults using the timeout options.
How does fx.Module differ from just grouping fx.Provide calls?
fx.Module creates a scoped namespace for dependencies, allowing decorators (fx.Decorate) to apply only within that module's scope. Modules are the unit of reuse in fx applications, making it easier to compose large service graphs and avoid decorator conflicts between unrelated subsystems.
Can I use fx with existing code that doesn't use dependency injection?
Yes. You can use fx.Supply to inject pre-constructed values into the container, and fx.Invoke to bridge fx-managed dependencies with legacy initialization code. This allows incremental adoption without rewriting the entire application at once.
What tools are required to use this skill?
You need Go installed in your environment. The skill supports additional tooling like golangci-lint for code quality and git for version control, but the core requirement is the Go toolchain to install and use go.uber.org/fx.
Install golang-uber-fx
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
samber/cc-skills-golang