I am currently writing an application that runs in an OSGi environment.
For the visualization part I am using JavaFX. Each UI element is a dockable view that extends BorderPane. Its content is described using the fx:root element in a fxml file. Some of those UI elements need to access services within the OSGi container (for example a button in a view might trigger the save action which needs a reference to the PersistenceService).
What is the best way to achieve this?
The UI elements are automatically generated by a framework that I use. the only way to access services are the BundleActivator or the static method FrameworkUtil.getBundle().
My approach was to use the static utility method but after some more reading on the net I realized that you normally do not want to code against OSGi itself.
The other solution is using the scr annotations provided by Apache Felix. Marking the UI elements as @Component and referring each needed service via @Referencewould work. But is this good practice? Should I annotate them? I always though the classes referred by @Component are managed by OSGi itself and will always be instantiated by OSGi.