After some more experimentation, I've decided a factory is better than
the subclasses:

@Inject
public MyClient(MyClassFactory factory) {
  class1 = factory.create(MyEnum.A);
  class2 = factory.create(MyEnum B);
  class3 = factory.create(MyEnum C);
}

I also noticed the AssistedInject extension will would help me avoid
the factory implementation details.  However, it would be nice if
Guice could make those factory calls automatically (since the factory
parameters are known).  Any thoughts?

-Will

On Apr 22, 5:02 pm, Will Horn <[email protected]> wrote:
> I have a class where each instance is tied a unique enum value.  This
> enum value needs to be passed in as a parameter.  So
>
> enum MyEnum {A, B, C}
>
> @Inject
> public MyClass(SomeService service, MyEnum param)
>
> Clients are something like this:
>
> @Inject
> public MyClient(MyClass class1, MyClass class2, MyClass class3)  //
> class1 with enum A, class2 with enumB, class3 with enumC
>
> I would like to be able to annotate those dependencies on MyClass so
> that Guice knows which enum to create each of them with.  Is this
> possible?  If not, I can always create simple named subclass
> MyClassForA, MyClassForB, MyClassForC, but I'm getting used to Guice
> saving me from such things :o)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to