golang-uber-fx

Compose Go service dependency graphs with uber-go/fx lifecycle hooks.

1|Updated May 27, 2026
One-click install
npx skills add https://github.com/dmwin72015/netdisk --skill golang-uber-fx-dmwin72015
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-uber-fx
Source: https://github.com/dmwin72015/netdisk/tree/main/.agents/skills/golang-uber-fx
Command: npx skills add https://github.com/dmwin72015/netdisk --skill golang-uber-fx-dmwin72015

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

uber-go/fx helps you assemble complex Go application graphs while ensuring correct startup/shutdown behavior without relying on init() side effects.

Core Features & Use Cases

  • Lifecycle-safe service boot: Use fx.Lifecycle hooks (OnStart/OnStop) so long-running work starts and stops gracefully and deterministically.
  • Modular dependency injection: Compose large systems with fx.Module, and keep providers/invokes/decorators reusable and scoped.
  • Ergonomic wiring patterns: Use fx.New, fx.Provide, fx.Invoke, fx.Annotate (name/group/As), fx.Decorate, fx.Supply, and fx.Replace for production wiring and test overrides.
  • Run loop with signal awareness: app.Run blocks on SIGINT/SIGTERM and coordinates lifecycle hooks in the correct order.

Quick Start

Use the golang-uber-fx skill to structure your Go main() composition root with fx.New, register constructors with fx.Provide, trigger graph execution with fx.Invoke, and move server start/stop logic into fx.Lifecycle OnStart/OnStop hooks.

Frequently Asked Questions about golang-uber-fx

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

FAQPage Schema
How do I manage graceful startup and shutdown for long-running Go services?

Graceful startup and shutdown for Go services is managed by registering lifecycle hooks via fx.Lifecycle, ensuring deterministic OnStart and OnStop execution. This coordinates long-running workers and HTTP servers without relying on init() side effects.

How do I structure a Go main composition root for dependency injection?

Structure a Go composition root by calling fx.New, registering constructors with fx.Provide, and triggering graph execution with fx.Invoke. This builds the dependency graph at the application entry point to wire services safely.

How do I override dependencies for testing in a Go application graph?

Override dependencies for testing in a Go application graph by using fx.Supply to inject mock values and fx.Replace to swap providers. This allows test-time overrides while maintaining the existing fx graph structure.

Can I use dependency injection to compose modular gRPC and HTTP servers in Go?

Yes, you can compose modular gRPC and HTTP servers in Go by grouping providers with fx.Module. This scopes decorators and constructors, keeping large application graphs reusable and predictable during service boot.

How does signal handling work for blocking Go service run loops?

Signal handling for Go service run loops works by using app.Run, which blocks the application on SIGINT and SIGTERM. Upon receiving these signals, it coordinates the lifecycle hooks to ensure correct shutdown ordering.

What is the best way to bind interfaces and tag providers in a Go DI graph?

The best way to bind interfaces and tag providers in a Go DI graph is using fx.Annotate and fx.As. These ergonomic wiring patterns enable name and group tagging for predictable dependency resolution.