kratos使用wire进行依赖注入
报错:
$ make wire
cd cmd/qywx && wire
wire: E:projectenbrandsscrmappqywxcmdqywxwire.go:19:1: inject initApp: unused provider set "ProviderSet"
wire: E:projectenbrandsscrmappqywxcmdqywxwire.go:19:1: inject initApp: unused provider set "ProviderSet"
wire: git.dev.enbrands.com/interaction-market-cloud/go/scrm/app/qywx/cmd/qywx: generate failed
wire: at least one generate failure
../../app_makefile:100: recipe for target 'wire' failed
make: *** [wire] Error 1
$ make wire
cd cmd/qywx && wire
wire: E:projectenbrandsscrmappqywxcmdqywxwire.go:19:1: inject initApp: no provider found for git.dev.enbrands.com/interaction-market-cloud/go/scrm/app/qywx/internal/biz.MerchantRepo
needed by *git.dev.enbrands.com/interaction-market-cloud/go/scrm/app/qywx/internal/biz.MerchantUsecase in provider set "ProviderSet" (E:projectenbrandsscrmappqywxinternalbizbiz.go:6:19)
needed by *git.dev.enbrands.com/interaction-market-cloud/go/scrm/app/qywx/internal/service.MerchantService in provider set "ProviderSet" (E:projectenbrandsscrmappqywxinternalserviceservice.go:6:19)
needed by *github.com/go-kratos/kratos/v2/transport/http.Server in provider set "ProviderSet" (E:projectenbrandsscrmappqywxinternalserverserver.go:8:19)
needed by *github.com/go-kratos/kratos/v2.App in provider "newApp" (E:projectenbrandsscrmappqywxcmdqywxmain.go:38:6)
wire: git.dev.enbrands.com/interaction-market-cloud/go/scrm/app/qywx/cmd/qywx: generate failed
wire: at least one generate failure
../../app_makefile:100: recipe for target 'wire' failed
make: *** [wire] Error 1
解决方案
依赖注入过程中参数是层层注入实现 根据调用链路 确保每一层调用的参数都被实例化了
具体详细见 实践案例代码>>>