vipx / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Binding assisted inject factory to a named annotation #790

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Description of the issue:

1)I have created a Factory using Assisted Inject.
2)I want this factory to be bound to a named annotation.

Current solution
 bind(MyFactory.class).annotatedWith(Names.named("MyFactoryTest"))        .toProvider(FactoryProvider.newFactory(MyFactory.class, MyFactoryTest.class));

Issue: 

FactoryProvider is a deprecated class, and FactoryModuleBuilder class should be 
used, like below.

Module factoryModuleBuilder = new FactoryModuleBuilder()                        
                      implement(MyInterface.class,     MyInterfaceTest.class)   
                                              .build(MyFactory.class);

install(factoryModuleBuilder);

I would like to know how to get through this. I am not sure if this is an 
issue, but I did not find a forum to post my question. Apologies for the 
inconvenience.

Steps to reproduce:
1.
2.
3.

Original issue reported on code.google.com by devesh.m...@gmail.com on 11 Dec 2013 at 8:48

GoogleCodeExporter commented 9 years ago
Use the "build(Key<F> factoryInterface)" method to bind the factory with a 
binding annotation:

   Module factoryModuleBuilder = new FactoryModuleBuilder()
      .implement(MyInterface.class, MyInterfaceTest.class)
      .build(Key.get(MyFactory.class, Names.named("MyFactoryTest")));

   install(factoryModuleBuilder);

PS. you can ask questions on google-guice@googlegroups.com or on 
stackoverflow.com with the tag "guice".

Original comment by mccu...@gmail.com on 11 Dec 2013 at 12:41

GoogleCodeExporter commented 9 years ago

Original comment by mccu...@gmail.com on 11 Dec 2013 at 12:42

GoogleCodeExporter commented 9 years ago
Thank you for the information, it works as I needed. I shall make sure not to 
raise issues and use the sources you have provided. Thanks

Original comment by devesh.m...@gmail.com on 11 Dec 2013 at 12:51