Assisted Inject autowiring
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 1.7k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
Hey guys,
I'd like to dig-up [this](https://groups.google.com/forum/#!topic/google-guice-dev/FYWtMR9G31E) old issue.
I've attached some code we have in production now relating to assisted inject. Its a neat feature that we're using extensively, and would really like to continue using, without expanding our current configuration stuff any more.
What I would really like is for guice to auto discover factories. Its become convention on our class to simply put the factory interface above the constructor, so we have many classes like this:
``` Java
public class SomeController{
public interface Factory{
public SomeController create(List parentList);
}
@Inject
public SomeController(EventBus eventBus, OtherCoolServices services, @Assisted List parentList){
this.thing = //...
}
//...
}
```
the problem is that when we add a factory, we have to find out which flow is using that factory and make sure the modules are updated --probably the typical reason for auto-wiring over explicit configuration.
So yeah, please make this happen!
---
Said snippit, _I warned you_...
``` Java
private void bindFactory(Class factoryClass){
install(builder.build(factoryClass));
}
@Override
protected void configure() {
bindFactory(Project.Factory.class);
bindFactory(ExcelExporterService.Factory.class);
bindFactory(HistoryRewriter.Factory.class);
bindFactory(ProjectHistoryArchiveBuildingWalker.Factory.class);
bindFactory(Heartbeat.Factory.class);
installEventBus();
installPopupHost();
installUIComponents();
installNodeBehaviours();
bindExceptionHandlingFacilities();
}
private void installBootstrappingFacilities() {
bind(new TypeLiteral>() {}).toInstance(bootstrappingCompletionTasks);
bindFactory(SerializationConfiguration.Factory.class);
bindFactory(ProblemSetupBootstrapper.ProblemSetupModule.Factory.class);
bindFactory(ExternalToolBootstrapper.ExternalToolModule.Factory.class);
bind(ProblemSetupControllerFactory.class).to(ProblemSetupBootstrapper.class);
bind(ExternalToolControllerFactory.class).to(ExternalToolBootstrapper.class);
bindFactory(VisualizationBootstrapper.VisualizationModule.Factory.class);
}
private void bindExceptionHandlingFacilities() {
bindFactory(ErrorBalloonController.Factory.class);
bindFactory(ErrorDetailsPresentationFXController.Factory.class);
}
private void installUIComponents() {
bind(String.class).annotatedWith(Bindings.ProgramTitle.class).toInstance(DisplayValues.ProgramTitle);
bind(PointValidatingService.class).to(PointValidatingService.Tautology.class);
bindFactory(SelectPathAndSetTextListener.Factory.class);
bindFactory(FilePathSolicitingDialogController.Factory.class);
bindFactory(WorkspaceBlockController.Factory.class);
bindFactory(WorkspaceProblemsDialogController.Factory.class);
bindFactory(WorkspaceProblemLineItemController.Factory.class);
bindFactory(ProjectLogGroupController.Factory.class);
bindFactory(ProjectLogEntryController.Factory.class);
bindFactory(NotificationControl.Factory.class);
bindFactory(InvalidInputDialogBoxFXController.Factory.class);
bindFactory(ProjectCloseDialogFXController.Factory.class);
bindFactory(OptimizerSettingsPanelFXController.Factory.class);
bindFactory(StartOptionChooserController.Factory.class);
}
private void installNodeBehaviours() {
bindFactory(ETSurrogateJSONTranscodingService.Factory.class);
bindFactory(ExperimentNodeUserInterfaceBehaviour.Default.Factory.class);
bindFactory(ProblemDefinitionNodeBehaviour.Factory.class);
bindFactory(ExternalToolBridgeNodeBehaviour.Factory.class);
bindFactory(ProxyNodeBehaviour.Factory.class);
bindFactory(OptimizerNodeBehaviour.Factory.class);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.