FactoryModuleBuilder factory annotation question

70 views
Skip to first unread message

Leigh Klotz

unread,
Jun 8, 2010, 6:00:35 PM6/8/10
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.

Sam Berlin

unread,
Jun 8, 2010, 8:34:12 PM6/8/10
to google...@googlegroups.com, google-guice
Yes, I believe using Key.get (as you wrote) is how to do it. That's a
good idea to update the documentation -- I will add something to the
javadocs.

Sam

> --
> You received this message because you are subscribed to the Google
> Groups "google-guice" group.
> To post to this group, send email to google...@googlegroups.com.
> To unsubscribe from this group, send email to google-guice...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/google-guice?hl=en
> .
>

Leigh Klotz

unread,
Jun 8, 2010, 8:49:44 PM6/8/10
to google-guice
Thank you. It does work, but I wasn't sure if it's what was
intended. With the new documentation I will be!

Leigh.

On Jun 8, 5:34 pm, Sam Berlin <sber...@gmail.com> wrote:
> Yes, I believe using Key.get (as you wrote) is how to do it. That's a  
> good idea to update the documentation -- I will add something to the  
> javadocs.
>
> Sam
>
Reply all
Reply to author
Forward
0 new messages