An add on for Fx:
- add
func MultiProvide() fx.Option
.
We recommend locking to SemVer range ^1
using go mod:
go get go.uber.org/fx@v1
go get github.com/kittizz/fxx
func main() {
fx.New(
fxx.MultiProvide(
repository.NewRepository,
user_service.NewUserService,
),
fx.Invoke(
func(
userRepo *user_repository.UserRepository,
orderRepo *order_repository.OrderRepository,
) {
fmt.Println("Loadin :", userRepo.GetUser())
for k, v := range orderRepo.List() {
fmt.Println("My Order >", "["+k+"]", v)
}
os.Exit(0)
},
),
).Run()
}
....
package repository
var NewRepository = fxx.Modules(
user_repository.NewUserRepository,
order_repository.NewOrderRepository,
)
....
package user_service
func NewUserService() *UserService {
return &UserService{}
}