-
-
Notifications
You must be signed in to change notification settings - Fork 3k
DI Part A #11342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
# Conflicts: # src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java # src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small nitpick comments ^^
| PreferencesService preferencesService = Injector.instantiateModelOrService(PreferencesService.class); | ||
| BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it possible to Injector.instantiateModelOrService(ImportFormatPreferences)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require to register the ImportFormatPreferences at launch time of jabref in the afterburner. Now we have lazy loading implemented. Would probably increase the launch time, as some of the preferences objects require some more construction time.
| preferencesService.getXmpPreferences(), | ||
| preferencesService.getFilePreferences(), | ||
| preferencesService.getLibraryPreferences().getDefaultBibDatabaseMode(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it possible to
Injector.instantiateModelOrService(XmpPreferences.class),
Injector.instantiateModelOrService(FilePreferences.class),
Injector.instantiateModelOrService(LibraryPreferences.class),There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
| preferencesService.getLibraryPreferences().getDefaultBibDatabaseMode(), | ||
| Globals.entryTypesManager, | ||
| Injector.instantiateModelOrService(BibEntryTypesManager.class), | ||
| preferencesService.getFieldPreferences(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Injector.instantiateModelOrService(FieldPreferences.class),There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
| * @param pr The result of the BIB parse operation. | ||
| */ | ||
| void performAction(ParserResult pr, DialogService dialogService); | ||
| void performAction(ParserResult pr, DialogService dialogService, PreferencesService preferencesService); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't the injector be used "downstream"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a proper DI framework, yes. In the next iteration step
| fieldColumn.setCellValueFactory(cellData -> BindingsHelper.constantOf(cellData.getValue())); | ||
| new ValueTableCellFactory<Field, Field>() | ||
| .withText(FieldsUtil::getNameWithType) | ||
| .withText(item -> FieldsUtil.getNameWithType(item, preferencesService, undoManager)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the Injector be used inside FieldsUtil to keep the method signature small?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be argued. For me the idea was the same with EntryEditor and the RelatedArticlesTab. As afterburner is not an di framework it just provides injection for a presenter in the PresenterFactory. Using the Injector class is not really the intended use and would not be really cleaner than using the Globals class. So I decided for constructor injection here.
| styleSource, | ||
| outputFormat, | ||
| stateManager.getActiveDatabase().get(), | ||
| Injector.instantiateModelOrService(BibEntryTypesManager.class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't the Injector be used inside CitationStyleGenerator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, could be, but using a proper DI framework is just the next iteration step.
| pdfIndexer = PdfIndexerManager.getIndexer(Globals.stateManager.getActiveDatabase().get(), Globals.prefs.getFilePreferences()); | ||
| StateManager stateManager = Injector.instantiateModelOrService(StateManager.class); | ||
| PreferencesService preferencesService = Injector.instantiateModelOrService(PreferencesService.class); | ||
| pdfIndexer = PdfIndexerManager.getIndexer(stateManager.getActiveDatabase().get(), preferencesService.getFilePreferences()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Injector inside PdfIndexerManger to get an instance of FilePrefererences instead of using the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using contructor injection is always the cleanest solution for testing. About injection of smaller objects see above. Would require to abandon lazy loading of the preferences objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked at jvm-german for the first point (https://jvm-german.slack.com/archives/C4HLX61PY/p1717757611057629).
For the second point, I don't fully understand as I thought that DI really leads to lazy loading, because the injection happens at the latest possible time (if the Injector is called directly). Let's first solve the general discussion injection via constructor vs. injection at variables vs. injection using direct calls. And then, the other things will also get solves surely.
# Conflicts: # src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java
# Conflicts: # src/main/java/org/jabref/gui/fieldeditors/optioneditors/OptionEditor.java
# Conflicts: # src/main/java/org/jabref/gui/entryeditor/EntryEditor.java # src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java # src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java
# Conflicts: # src/main/java/org/jabref/gui/entryeditor/EntryEditor.java # src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java # src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.java # src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java # src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java # src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java # src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java
|
Update: We had some remote branch issues (same branch name on two upstreams). |
|
The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build. |
|
@calixtus, saving preferences throws an exception: |
|
Thanks. Hotfix created. |
First step towards implementing proper dependency injection (DI)
Major changes
Follows JabRef#687
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if applicable)