NoobProg
NoobProg

Reputation: 91

Binding to 2 classes to the same interface

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?

Upvotes: 0

Views: 123

Answers (1)

ThisIsNoZaku
ThisIsNoZaku

Reputation: 2443

Don't bind both at once.

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

Upvotes: 4

Related Questions