bind.toInstance() vs @Singleton

971 views
Skip to first unread message

Aleksey Matsarski

unread,
Apr 8, 2016, 3:34:25 AM4/8/16
to google-guice
What is the difference between bind.toInstance() and @Singleton? Will be the result - singleton for both? 

Laszlo Ferenczi

unread,
Apr 8, 2016, 3:52:29 AM4/8/16
to google...@googlegroups.com
The difference is who instantiates the class. 
@Singleton will be guice instantiated (and therefore can participate in AOP for example), toInstance() expects an instance which is already created, AOP is not possible for this type of binding. 

--
L

On Fri, Apr 8, 2016 at 9:34 AM, Aleksey Matsarski <mat.al...@gmail.com> wrote:
What is the difference between bind.toInstance() and @Singleton? Will be the result - singleton for both? 

--
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.
To post to this group, send email to google...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/d7ad8464-afd0-40d0-ba55-0b84afcff2c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Pontarelli

unread,
Apr 8, 2016, 12:19:25 PM4/8/16
to google...@googlegroups.com
And constructor injection isn't possible for toInstance() 

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages