Files
backend/internal/app/module.go

31 lines
886 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package app 提供 uber-go/fx 应用装配层。
//
// 该包用 fx 的 Provider/Lifecycle 取代了 pkg/*/manager.go 的全局单例和
// internal/container 的手动 DI是整个应用唯一的依赖装配入口。
//
// 使用方式:
//
// cfg, err := config.Load()
// if err != nil { log.Fatal(err) }
// fx.New(app.Module(cfg)).Run()
package app
import (
"carrotskin/pkg/config"
"go.uber.org/fx"
)
// Module 返回应用的根 fx.Option聚合所有子模块。
// cfg 通过 fx.Supply 注入,供各 Provider 消费其子配置结构。
//
// 当前阶段fx 管理 infra + Container 聚合 + 路由/服务器/任务生命周期。
// Container 内部构造 Repository 与 Service阶段6后将逐步解耦为 fx 直接管理 Service
func Module(cfg *config.Config) fx.Option {
return fx.Options(
fx.Supply(cfg),
InfraModule,
BootstrapModule,
)
}