1

I'm new with Java Guice, and I have trouble with designing my application.
I'll try to explain my design and the desired result as simple as I can.

I have an interface called Ialgorithm, and 3 implementations of that interface, lets say IalgorithmA,IalgorithmB,IalgirthmC.

I have a class called myClass with the following constructor:

public myClass(Ialgorithm alg) {...}

Now I want to be able to inject an instance of one of the implementations of the Ialgorithm interface, using annotations: I want at the end to be able to write in my main:

// ... intialize an Injector with a Moudle that extents AbstractModule
myClass a = injecotr.getInstance(key.get(myClass.class,Aannotation.class));
myClass b = injecotr.getInstance(key.get(myClass.class,Bannotation.class));
myClass c = injecotr.getInstance(key.get(myClass.class,Cannotation.class));

I read a few tutorials in the web, but I couldn't find exact way to achieve this.

In addition, and after the above issue will be solved, I extend my question: Actually, The third implementation, IalgirthmC, is different from the two other implementations which contain a default constructor: its constructor is:

public IalgorithmC(Ialgorithm,int n) {...}

Now it becomes more complicated... because I want the Guice to inject the Ialgorithm parameter, but the int parameter shouldn't injected by the Guice (@Assisted), and this whole instance of IalgorithmC should be injected into myClass when using the Cannotaion.
Of course that I should provide a value for the int parameter and an annotation to the internal Ialgorithm in IalgorithmC.

Thank you all for any help.

1 Answer 1

1

This question talk about one solution for multiple implementations in guice.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.