0

I have an interface interfaceA, classes classA and classB. classA implements interfaceA, classB implements interfaceA. classA has business logic and classB is a mocker used for testing purpose. I want to bind

 bind(interfaceA.class).to(classA.class).in(Singleton.class);
 bind(interfaceA.class).to(classB.class).in(Singleton.class);

In essence, I always want logic in classA to always be used whenever any method of interface is called and classB to be used for testing the classA implementation.

But when I bind it in the above fashion, I get an error complaining a binding is already defined, can't define binding again for interfaceA. How do I effectively solve this?

NoobProg
  • 81
  • 1
  • 4
  • 10
  • Does this answer your question? [Overriding Binding in Guice](https://stackoverflow.com/questions/483087/overriding-binding-in-guice) – Progman Jul 11 '20 at 15:54

1 Answers1

4

Don't bind both at once.

In your test configuration, bind the test version and in your production one, bind the real implementation.

ThisIsNoZaku
  • 2,213
  • 2
  • 26
  • 37