DMwangnima opened a new issue, #2377: URL: https://github.com/apache/dubbo-go/issues/2377
<!-- Please only use this template for submitting enhancement requests --> **Why is this needed**: 这个issue由之前的提案(#2375)引出,拆分出client模块后,为了让NewClient可以完全与config.Load等价,还需要注入config.RootConfig和config.ConsumerConfig,以完成ReferenceConfig.Init流程。但config模块也会依赖client模块,这样就造成了循环依赖。根本原因在于config模块中的大部分配置都会直接感知上层配置,以client侧的Root->Consumer->Reference配置结构为例,ReferenceConfig.Init(rc *RootConfig)中会直接引用RootConfig和ConsumerConfig。 **What would you like to be added**: 为了达到上层模块依赖下层模块,下层模块感知不到上层模块的效果,考虑将ReferenceConfig.Init(rc *config.RootConfig)改成ReferenceConfig.Init(opts ...ReferenceOption),ConsumerConfig.Init在调用client.ReferenceConfig.Init时,将所需的配置都以client.ReferenOption数组的形式传入。以下是代码转变: ```go // old code func (cc *ConsumerConfig) Init(rc *RootConfig) error { // 省略 for key, referenceConfig := range cc.References { if err := referenceConfig.Init(rc); err != nil { return err } } // 省略 } ``` ```go // new code func (cc *ConsumerConfig) Init(rc *RootConfig) error { // 省略 cc.refOpts = []client.ReferenceOption{ client.WithFilter(cc.Filter), client.WithRegistryIDs(cc.RegistryIDs), client.WithProtocol(cc.Protocol), client.WithTracingKey(cc.TracingKey), client.WithCheck(cc.Check), client.WithMeshEnabled(cc.MeshEnabled), client.WithAdaptiveService(cc.AdaptiveService), client.WithProxyFactory(cc.ProxyFactory), } for key, referenceConfig := range cc.References { if err := referenceConfig.Init(cc.refOpts...); err != nil { return err } } // 省略 } ``` **Extended** 将ReferenceConfig移动到client模块,config模块依赖client模块可以引申到其他配置,将这些配置移动到各自的模块,例如将RegistryConfig移动到registry模块中,config模块依赖registry模块。这部分的工作将和#2343 dubbo模块拆解与重构计划直接挂钩。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org