Re: How to get guice to provide a unique instance with a provider?

15 views
Skip to first unread message

Stephan Classen

unread,
Aug 24, 2014, 5:19:16 PM8/24/14
to google...@googlegroups.com

I never used provide methods, but you can add the @Singleton annotation to the provided class.

Am 24.08.2014 16:57 schrieb Maatary Okouya <maatar...@gmail.com>:
I have the following on the guice website with few explanation:

  @Provides @Singleton
  TransactionLog provideTransactionLog() {
    ...
  }

Is that the solution. Does the singleton apply to the provider or the provided. If it applies to the provider then, the solution would be to retain one instance and return it each time. But that would not work with a provide method.
Any help ?

On Sunday, August 24, 2014 4:38:06 PM UTC+2, Maatary Okouya wrote:
Hi, 


I have an object A that does some important loading. I use a provider for it. I have object B that needs A for its initialization. However in an object C I want to pass A, and B, properly prepared. 

Would it be possible to get a provider to return the same instance all the time, or the guice module to keep that instance provided and stop right there?


Many thanks,

-M-

--
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 http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/7d1352b4-cfe1-4397-8309-1694336bbcfa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages