2

I'm new at OSGI and Declarative Services, and I'm trying to implement a strategy, but I'm having trouble to get components Satisfied and/or Active

Implementation Diagram

My BillConfig has the useMocks(), when it's true the Repo that should be returned by the factory is the BillRepositoryInMemory, otherwise should be the BillRepositoryREST. How can I have access to an abstraction of this repos in my BillDAO?

Thanks

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
Marco Sousa
  • 185
  • 1
  • 1
  • 9

1 Answers1

1

Your setup with a Factory does not look optimal for OSGi usage. Instead I propose to create the repository impls as DS components with a required config policy.

This way you can activate the repo impl component you want by supplying it with a config.

In BillDAO you can then use:

@Reference
BillRepository repo;

This approach completely avoids the Factory pattern and makes your components much more loosely coupled.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64