From my understanding the injection order should not be important in any way, or said in a better way, you should never rely on it. Your component gets satisfied once all required dependencies are resolved. So there is no component instance until all references can be resolved and injected, therefore you cannot do anything with that component before. If you have an optional dependency, the component is satisfied once the mandatory dependency can be resolved, the optional one is not taken into account here. So you cannot rely anywhere in that component that the optional dependency is set at all and always need a null check to be safe. And as Tim already said, dynamic services can come and go at any time without creating a new component instance, so you always need to be careful here.
Mit freundlichen Grüßen / Best regards Dirk Fauth Automotive Service Solutions, ESI application (AA-AS/EIS2-EU) Robert Bosch GmbH | Postfach 11 29 | 73201 Plochingen | GERMANY | www.bosch.com<http://www.bosch.com> Tel. +49 7153 666-1155 | dirk.fa...@de.bosch.com<mailto:dirk.fa...@de.bosch.com> Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart, HRB 14000; Aufsichtsratsvorsitzender: Franz Fehrenbach; Geschäftsführung: Dr. Volkmar Denner, Prof. Dr. Stefan Asenkerschbaumer, Dr. Rolf Bulander, Dr. Stefan Hartung, Dr. Markus Heyn, Dr. Dirk Hoheisel, Christoph Kübel, Uwe Raschke, Peter Tyroller Von: osgi-dev-boun...@mail.osgi.org [mailto:osgi-dev-boun...@mail.osgi.org] Im Auftrag von Tim Ward via osgi-dev Gesendet: Mittwoch, 31. Januar 2018 12:43 An: Thomas Driessen <thomas.driessen...@gmail.com>; OSGi Developer Mail List <osgi-dev@mail.osgi.org> Betreff: Re: [osgi-dev] DS Reference injection order Firstly - why do you need to rely on this? It sounds like very fragile code to me and you should probably consider rewriting so that you don’t need to care. However... Section 112.5.7 of the compendium says that: When binding services, the references are processed in the order in which they are specified in the component description. That is, target services from the first specified reference are bound before services from the next specified reference. A static optional service will not be set if it is not satisfied, or will if it is. A dynamic optional service will behave the same way, but it may be unset and reset many times afterwards on other threads. Dynamic services should always be treated with care, whether they are optional or not. Tim On 31 Jan 2018, at 10:50, Thomas Driessen via osgi-dev <osgi-dev@mail.osgi.org<mailto:osgi-dev@mail.osgi.org>> wrote: Hi, I searched the compendium spec but didn't find what I was looking for. If I have a DS with multiple references to other DS @Component class Example1{ @Reference Example2 e2 @Reference Example3 e3 } in which order are the references injected? Is there even a deterministic order? In the above example both references are static/mandatory. What happens if I have a static/mandatory and a dynamic/optional one like this: @Component class Example1{ @Reference Example2 e2 @Reference volatile Example3 e3 } Kind regards, Thomas _______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org<mailto:osgi-dev@mail.osgi.org> https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev