public class Example implements ExampleInterface {
  private final int moduleId;
  public Example(int moduleId){
    this.moduleId = moduleId;
  }
}

In my Guice module, I do

@Provides @Module1
private ExampleInterface provideModule1Example(@Module1 int moduleId){
  return new Example(moduleId);
}

@Provides @Module2
private ExampleInterface provideModule2Example(@Module2 int moduleId){
  return new Example(moduleId);
}

So, injecting an ExampleInterface, annotated with either @Module1 or 
@Module2, uses the same implementation, just with a different parameter. If 
I want to add an AssistedInject parameter to the constructor, and create a 
factory for it, I'd have something like

public interface ExampleInterfaceFactory {
  ExampleInterface create(Object someParameter);
}

I'd want to annotate someParameter, but the annotation would depend on how 
the ExampleInterface is annotated where it's injected.

I hope that all makes sense. I'm still fairly new to Guice...



On Wednesday, 1 October 2014 19:42:58 UTC-5, Nate Bauernfeind wrote:
>
> Can you explain what you mean with a small amount of code? Can you 
> annotate the assisted inject factories? Maybe you can mix PrivateModule's 
> along with AssistedInject factories to get the effect you're looking for 
> (and potentially exposing the factory with an annotation?).
>
> Nate
>
> On Wed, Oct 1, 2014 at 6:38 PM, Brad Micholson <fouro...@gmail.com 
> <javascript:>> wrote:
>
>> I'm wondering if there's a better way to do this than I'm currently 
>> doing...
>>
>> I want to, essentially, bind multiple configurations of a class, based on 
>> an annotation. I don't want a separate class binding for different 
>> annotations; I just want different parameters in the constructor. Right 
>> now, I'm creating multiple providers, which contain differently annotated 
>> parameters.
>> However, I'd love to be able to use AssistedInject, as I find I'm 
>> creating a ton of factory classes. There doesn't really seem to be a way to 
>> do that. I'd initially thought I could maybe create multiple abstract 
>> implementations of the factory, and annotate the parameters, but it seems 
>> the factory must be an interface...
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "google-guice" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to google-guice...@googlegroups.com <javascript:>.
>> To post to this group, send email to google...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/google-guice.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/google-guice/b8e3782d-53f9-42a4-b0d4-8e148c56323d%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/google-guice/b8e3782d-53f9-42a4-b0d4-8e148c56323d%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/ef53ac16-bccd-458a-b938-e18c55214166%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to