1

Let's assume I have a Front End App which needs to fetch data from some backend. And let's assume that there are 2 different backend REST APIs implementations available, BackEnd1 and BackEnd2. They both offer the same semantics, so the client can consume either of them, but the structure of their Input/Output pairs are different.

To mask these differences I can create an interface BackEndInterface which defines the methods that the client will call and provide 2 implementation classes, BackEndImpl1 and BackEndImpl2, for BackEnd1 and BackEnd2 respectively. Which one to use is decided using the Dependency Injection (DI) mechanisms.

The question is whether it is possible to drive DI using an external configuration and so decide at at the startup of the application, e.g. reading an environment variable or a configuration file, which implementation to use.

Picci
  • 16,775
  • 13
  • 70
  • 113

0 Answers0