title: Is it good practice to use OSGi DS on UI elements?
body: <p>I am currently writing an application that runs in an OSGi environment. </p>
  
  <p>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). </p>
  
  <p>What is the best way to achieve this? </p>
  
  <p>The UI elements are automatically generated by a framework that I use. the only way to access services are the <code>BundleActivator</code> or the static method <code>FrameworkUtil.getBundle()</code>. </p>
  
  <p>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. </p>
  
  <p>The other solution is using the scr annotations provided by Apache Felix. Marking the UI elements as <code>@Component</code> and referring each needed service via <code>@Reference</code>would work. But is this good practice? Should I annotate them? I always though the classes referred by <code>@Component</code> are managed by OSGi itself and will always be instantiated by OSGi.  </p>