Skip to content

Commit

Permalink
Add some text on DI
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed May 27, 2024
1 parent 9aa8cc4 commit 5a085e1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs/code-howtos/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ See also [High Level Documentation](../getting-into-the-code/high-level-document

We really recommend reading the book [Java by Comparison](http://java.by-comparison.com).

Please read [https://github.com/cxxr/better-java](https://github.com/cxxr/better-java)
Please read <https://github.com/cxxr/better-java>.

* try not to abbreviate names of variables, classes or methods
* use lowerCamelCase instead of snake\_case
* name enums in singular, e.g. `Weekday` instead of `Weekdays` (except if they represent flags)

## Dependency injection

JabRef uses a [fork](https://github.com/JabRef/afterburner.fx) of the [afterburner.fx framework](https://github.com/AdamBien/afterburner.fx) by [Adam Bien](https://adam-bien.com/).

The main idea is to get instances by using `Injector.instantiateModelOrService(X.class)`, where `X` is the instance one needs.
The method `instantiateModelOrService` checks if there is already an instance of the given class. If yes, it returns it. If not, it creates a new one.

In case a class needs parameters in the constructor, one needs to modify `org.jabref.gui.DefaultInjector#createDependency` to call the constructor with the appropriate parameters.
In case this way is not applicable, one can use `com.airhacks.afterburner.injection.Injector#registerExistingAndInject(T)` to register an existing instance with the injector.

## Cleanup and Formatters

We try to build a cleanup mechanism based on formatters. The idea is that we can register these actions in arbitrary places, e.g., onSave, onImport, onExport, cleanup, etc. and apply them to different fields. The formatters themselves are independent of any logic and therefore easy to test.
Expand Down

0 comments on commit 5a085e1

Please sign in to comment.