You might want to consider using Multibindings, which allows users to add additional dependencies to Set<T>or Map<K,V>. Here is an example:
interface Plugin {
void install(Application application);
}
@Component({ModuleA.class, ModuleB.class})
interface PluginComponent {
Set<Plugin> plugins();
}
@Module
class ModuleA {
@Provides(type = SET) Plugin providFooPlugin() {
return new FooPlugin();
}
}
@Module
class ModuleB {
@Provides(type = SET) Plugin providBarPlugin() {
return new BarPlugin();
}
}
, . - @Provides(type = SET_VALUES) , , Collections.emptySet(). :
interface Plugin {
void install(Application application);
}
@Component({ModuleA.class, ModuleB.class})
interface PluginComponent {
Set<Plugin> plugins();
}
@Module
class ModuleA {
private final Set<Plugin> plugins;
ModuleA(Set<Plugin> plugins) {
this.plugins = plugins;
}
@Provides(type = SET_VALUES) Plugin providFooPlugins() {
return plugins;
}
}
@Module
class ModuleB {
@Provides(type = SET) Plugin providBarPlugin() {
return new BarPlugin();
}
}
:
DaggerPluginComponent.builder()
.moduleA(new ModuleA(Collections.emptySet())
.build();
, :
Set<Plugin> plugins = new HashSet<>();
plugins.add(new AwesomePlugin());
plugins.add(new BoringPlugin());
DaggerPluginComponent.builder()
.moduleA(new ModuleA(plugins)
.build();