kezhenxu94 commented on PR #9828:
URL: https://github.com/apache/skywalking/pull/9828#issuecomment-1286787021

   > The root cause of this change is when I want to extend an existing module 
provider to another, but need to add new configurations. In the previous 
implementations, most providers have to hold a field/pointer to the 
configuration, in order to use it in `init`/`start`/... stages. This should be 
fine until we want to extend and add a new configuration, a new configuration 
class could inherit from the existing config, but the new provider can't 
inherit the existing provider, because you can't inject the extended config to 
replace the config instance created and hold in the old provider.
   
   Hi, this is how I extend the provider AND the configuration. Let's take 
`AnalyzerModuleProvider` as an example.
   
   - Extend the configuration
   
   ```java
   public class MyAnalyzerModuleConfig extends AnalyzerModuleConfig {
     // This is my new configuration
     @Getter
     @Setter
     private String myNewConfiguration;
   }
   ```
   
   - Extend the provider
   
   ```java
   
   public class MyAnalyzerModuleProvider extends AnalyzerModuleProvider {
     private final MyAnalyzerModuleConfig newModuleConfig;
   
     public MyAnalyzerModuleProvider(MyAnalyzerModuleConfig newModuleConfig) {
       this.newModuleConfig = newModuleConfig;
     }
   
     @Override
     public ModuleConfig createConfigBeanIfAbsent() {
         return newModuleConfig;
     }
   
     @Override
     public void prepare() throws ServiceNotProvidedException, 
ModuleStartException {
         this.registerServiceImplementation(MyService.class, new 
MyService(newModuleConfig));
     }
   }
   ```
   
   - And the new service
   
   ```java
   
   public class MyAnalyzerModuleConfig extends AnalyzerModuleConfig {
     // This is my new configuration
     @Getter
     @Setter
     private String myNewConfiguration;
   }
   ```
   
   
   Did I understand correctly? Do we have anything new in this PR that we can't 
do in the previous implementation?


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to