My Component and and application file are getting very large and the same code base serves multiple brands. We want to conditionally inject modules depending on certain config. Is there any way to do this.
Our current code base looks something like this.
public class SupportPortalApplication extends Application<SupportPortalConfiguration> {
...
private void initializeComponent() {
if (component == null) {
component = DaggerSupportPortalComponent.builder()
.moduleOne(new ModuleOne())
.moduleTwo(new ModuleTwo())
.moduleThree(new ModuleThree())
.build();
}
}
private void registerEndpoints(Environment environment) {
environment.jersey().register(component.getResourceModule1());
environment.jersey().register(component.getResourceModule2());
environment.jersey().register(component.getResourceModule3());
}
...
}
@Singleton
@Component(modules = {ModuleOne.class, ModuleTwo.class, ModuleThree.class})
public interface SupportPortalComponent {
ModuleOne getModuleOne();
ModuleTwo getModuleTwo();
ModuleThree getModuleThree();
}
I want to be able to conditionally load module three, along with its routes. It is easy to just remove the .moduleThree(new ModuleThree()) from the initializeComponent function conditionally but I would need a way to remove it as a module in the SupportPortalComponent. Is there any way to do this?
DropwizardVersion: "1.3.5"
DaggerVersion:"2.29.1"
Github Question:
https://github.com/dropwizard/dropwizard/issues/3982