golang-uber-fx

Wire Go service dependencies with uber-go/fx modules, lifecycle hooks, and value groups.

Updated May 9, 2026
One-click install
npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-uber-fx-luminavault
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-uber-fx
Source: https://github.com/LuminaVault/LuminaVaultShared/tree/main/.agents/skills/golang-uber-fx
Command: npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-uber-fx-luminavault

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires go.uber.org/fx, and includes references (resource) components.

What problem does it solve? Structuring a long-running Go service with uber-go/fx involves many subtle decisions — where to start servers, how to group providers, how to swap fakes in tests — and getting them wrong causes hung startups, leaked goroutines, or untestable wiring. This Skill guides an AI agent to apply idiomatic fx patterns correctly. ## Core Features & Use Cases - Application wiring: Compose fx.New with fx.Provide, fx.Invoke, fx.Supply, and fx.Module so main() stays thin and modules own their providers and decorators. - Lifecycle management: Register fx.Hook OnStart/OnStop callbacks that return quickly, respect context cancellation, and shut down gracefully under StartTimeout/StopTimeout. - Annotations and groups: Use fx.Annotate with fx.As, fx.ResultTags, and group tags to bind interfaces and collect many handlers into one consumer slice. - Testing patterns: Use fxtest.New, fx.Populate, and fx.Replace to pull services from the graph and swap real dependencies for fakes without rewriting modules. - Use Case: When adding an HTTP server to an fx app, the Skill directs the agent to inject fx.Lifecycle into the constructor, start srv.Serve in a goroutine inside OnStart, and call srv.Shutdown(ctx) in OnStop. ## Quick Start Ask the agent to wire your Go service with uber-go/fx, for example: "Refactor my main.go to use fx modules for the HTTP server and database with graceful shutdown."

Frequently Asked Questions about golang-uber-fx

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I start an HTTP server with uber-go/fx?▼

Inject fx.Lifecycle into your server constructor and append an fx.Hook. Call net.Listen and launch srv.Serve in a goroutine inside OnStart so the hook returns quickly, and call srv.Shutdown(ctx) in OnStop for graceful shutdown.

What is the difference between uber-go/fx and uber-go/dig?▼

fx is built on dig and shares the same DI primitives, but adds lifecycle hooks, a module system with scoped decorators, a signal-aware run loop, and structured event logging. Use fx for long-running services and raw dig for CLI tools or libraries that manage their own lifecycle.

How do I bind an interface to a constructor in fx?▼

Wrap the constructor with fx.Annotate and pass fx.As(new(YourInterface)), optionally adding fx.ResultTags for name or group tags. This keeps the original constructor unchanged and avoids writing a separate adapter or fx.Out struct.

How do I test fx wiring with fake dependencies?▼

Use fxtest.New(t, ...) with fx.Replace to swap a real provider for a fake, and fx.Populate(&target) to pull a service out of the graph. Call app.RequireStart() and defer app.RequireStop() so failures fail the test and cleanup runs automatically.

Why does my fx application hang during startup?▼

Startup hangs when an OnStart hook runs blocking work synchronously instead of spawning a goroutine, preventing dependent hooks from firing. Hooks must return quickly and respect context cancellation within the configured StartTimeout, which defaults to 15 seconds.

When should I use fx.Supply instead of fx.Provide?▼

Use fx.Supply for pre-built values such as parsed config, secrets, or command-line flags that already exist before fx.New runs. It avoids writing a no-op constructor like fx.Provide(func() *Config { return cfg }) and makes intent clearer.