For simplicity, you could probably let the framework do a bit more work for you and remove the need for the BundleContext field by using the reference bind method technique that sends you the service instance + the properties.
For example, something like this: private Map<String, DataSource> dataSources = new ConcurrentHashMap<>(); @Reference(service=DataSource.class, policy = DYNAMIC, cardinality=MULTIPLE) void bindDataSource(DataSource ds, Map<String, Object> properties) { dataSources.put((String) properties.getProperty("datasource.name"), ds); } void unbindDataSource(DataSource ds, Map<String, Object> properties) { dataSources.remove((String) properties.getProperty("datasource.name"), ds); } On Tue, Dec 15, 2020 at 8:13 AM Bertrand Delacretaz <bdelacre...@apache.org> wrote: > On Tue, Dec 15, 2020 at 4:58 PM Robert Munteanu <romb...@apache.org> > wrote: > > ...This way you get the datasources injected and via SCR and you get to > > use the datasource.name as a key... > > sounds good and it's certainly more efficient than what I suggested. > > -Bertrand >