Comment on UntargettedBindings in google-guice

84 views
Skip to first unread message

google...@googlecode.com

unread,
Jul 28, 2010, 10:51:39 AM7/28/10
to google-g...@googlegroups.com
Comment by illarion.kovalchuk:

is bind(MyConcreteClass.class); the same as

@Provides
MyConcreteClass provideMyConcreteClass(){
...
}

?


For more information:
http://code.google.com/p/google-guice/wiki/UntargettedBindings

google...@googlecode.com

unread,
Jul 28, 2010, 10:55:53 AM7/28/10
to google-g...@googlegroups.com
Comment by illarion.kovalchuk:

is {{{bind(MyConcreteClass?.class);}}} the same as
{{{
@Provides MyConcreteClass? provideMyConcreteClass(){ ... }

google...@googlecode.com

unread,
Jul 28, 2010, 1:13:18 PM7/28/10
to google-g...@googlegroups.com
Comment by drew.mclaughlin:

No.

An untargetted binding simply tells the injector that whenever an instance
of MyConcreteClass is requested it should create one and inject it. Whereas
the provides method tells the injector that this method should be invoked
whenever an instance of MyConcreteClass is requested and use the returned
value to inject.

The key difference is that the instance will be created by Guice in one
case and by your code in the other. There are a few things that will only
work for instance created by Guice - AOP method interception being the main
one.

In general I'd recommend that you only use provider methods when you've got
non-trivial logic required to create the instance. Usually this means that
you'll have a non-zero number of parameters to the provider method that
you'd use to create the instance.

google...@googlecode.com

unread,
Oct 25, 2012, 6:41:35 PM10/25/12
to google-g...@googlegroups.com
Comment by jeff12...@gmail.com:

Will you please show an example or two of how to use the untargeted
bindings with annotations?

google...@googlecode.com

unread,
Nov 28, 2012, 9:34:01 PM11/28/12
to google-g...@googlegroups.com
Comment by one...@gmail.com:

What is the purpose of Untargetted bindings?

google...@googlecode.com

unread,
Jan 20, 2013, 11:50:18 AM1/20/13
to google-g...@googlegroups.com
Comment by d...@iuservice.com:

I think that untargetted binding simply tell the injector that there is a
big chance that these types will be used soon, so better be prepared for
them if it has nothing else to do.

I think the main purpose of this is to improve performance.
It's obvious that preparing the entire Java dependency graph is not the way
to go. And telling Guice to prepare for what you think you will be using
during its downtime should be a good practice.
Reply all
Reply to author
Forward
0 new messages