Reputation: 6292
I have got a question about binding in Guice.
I have got two classes (MyClass1 and MyClass2) both implement the same interface, say: IMyInteface.
I have got the binding configured as:
bind(IMyInterface.class).annotatedWith(Class1.class).to(MyClass1.class); bind(IMyInterface.class).annotatedWith(Class2.class).to(MyClass2.class);
The Class1 and Class2 are annotations defined.
Now, if I use this code in the client:
Injector injector = Guice.createInjector(new MyModule());
IMyInterface c = injector..getInstance(IMyInterface.class);
The Guice won't know which implementation I want to have for IMyInterface. Is there anyway I can specify the annotation at this stage to selectively say: I want the implementation of MyClass2?
Many thanks
Upvotes: 1
Views: 2338