Leigh Klotz
unread,Jun 8, 2010, 6:00:35 PM6/8/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-guice
I have a question about how to apply an annotation to the resulting
factory with FactoryModuleBuilder. (In trunk, FactoryProvider is
deprecated in favor of FactoryModuleBuilder.)
Let's say I have an annotation @PrivateFeature which I use to control
availability of certain objects, and I want to apply this annotation
to an assistedinject factory.
In Guice-2.0 assistedinject, when I want to mark an assistedinject
Factory with @PrivateFeature, I annotate the resulting factory class,
like this:
bind(BundleFactory.class)
.annotatedWith(PrivateFeature.class)
.toProvider(FactoryProvider.newFactory(BundleFactory.class,
BundleImpl.class));
So, in order to get a BundleFactory, I happily inject "@PrivateFeature
BundleFactory".
With trunk FactoryModuleBuilder, the binding for BundleFactory.class
is hidden within the generated module, so I can't affect the binding
directly in order to add .annotatedWith.
Is this how I do it?
install(new FactoryModuleBuilder()
.implement(Bundle.class, BundleImpl.class)
.build(Key.get(BundleFactory.class,
PrivateFeature.class)));
It would be nice to have a brief example providing some guidance in
the FactoryModuleBuilder overview.
Thank you,
Leigh.