golang-uber-fx

Wire Go applications with uber-go/fx dependency injection, lifecycle hooks, and modules.

1|Updated Jun 2, 2026
One-click install
npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-uber-fx-verifiedorganic
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-uber-fx
Source: https://github.com/VerifiedOrganic/onboard/tree/main/.agents/skills/golang-uber-fx
Command: npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-uber-fx-verifiedorganic

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Structuring a long-running Go service means wiring dozens of constructors, managing startup and shutdown order, and handling signals correctly. This Skill guides AI agents to build fx application graphs correctly, avoiding common mistakes like blocking OnStart hooks, init()-based side effects, and forgotten fx.Invoke calls. ## Core Features & Use Cases - Application Wiring: Covers fx.New, fx.Provide, fx.Invoke, fx.Supply, fx.Replace, fx.Decorate, and fx.Annotate for name/group/interface bindings. - Lifecycle & Modules: Teaches fx.Lifecycle OnStart/OnStop hooks, fx.Module scoping, signal-aware Run(), and manual Start/Stop control for CLI embedding. - Testing Patterns: Includes fxtest.New, fx.Populate, fx.Replace for fakes, and CI graph validation via app.Err(). - Use Case: When a Go service's main.go accumulates dozens of fx.Provide calls, use this Skill to reorganize them into fx.Module groups with module-scoped decorators and graceful shutdown hooks. ## Quick Start Ask the agent to wire your Go service with uber-go/fx, for example: refactor my main.go to use fx.Module for the HTTP and database concerns with lifecycle hooks for 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 lifecycle hooks?▼

Inject fx.Lifecycle into your server constructor and append an fx.Hook. In OnStart, call net.Listen and launch srv.Serve in a goroutine so the hook returns quickly; in OnStop, call srv.Shutdown(ctx) 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, fx.Module 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 a constructor to an interface in fx?▼

Use fx.Annotate with fx.As, for example fx.Annotate(NewPostgresDB, fx.As(new(Database))). Add fx.ResultTags inside the same annotation for name or group tags, without writing a separate adapter constructor or fx.Out struct.

Why does my fx application hang during startup?▼

A blocking OnStart hook is the usual cause — long-running work must run in a goroutine so the hook returns quickly and dependent hooks can fire. Also verify every provided type is reachable from an fx.Invoke, since unreferenced constructors never run.

How do I test fx wiring with fake dependencies?▼

Use fxtest.New(t, ...) with fx.Replace to swap a real dependency for a fake, and fx.Populate(&target) to pull values out of the graph. Call app.RequireStart() and defer app.RequireStop() so failures call t.Fatal and teardown registers as cleanup.

When should I not use uber-go/fx?▼

Avoid fx for one-shot CLI tools or small object graphs where lifecycle and signal handling add no value — raw uber-go/dig or manual constructor injection is simpler. fx pays off when you need OnStart/OnStop ordering, modules, and graceful shutdown.