Discussion:
Providers - generation ?
c***@gmail.com
2018-02-12 12:19:38 UTC
Permalink
Hi all,

I apologise if my question sounds silly or badly grounded.

I am working on a project which makes intense use of Google Guice and I've
seen several places where the class I am working with uses injected
providers, such as:

class WhatEver {
@Inject
WhatEver(Provider<A> providerOfA ...) { ... }

}

I do not understand how/what implements the provider as I do not see any
class around my module explicitly implementing the interface.

Provider<A>


I am pretty sure there is not any.

How does that work ? Are providers synthesised/generated ? If yes I would
like to see where this is done - so I can have a better idea about how the
whole thing works.

Thanks in advance,
Pietro.
--
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/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2018-02-12 12:32:27 UTC
Permalink
Yes, Providers are generated on the fly by guice.

https://github.com/google/guice/wiki/InjectingProviders
Post by c***@gmail.com
Hi all,
I apologise if my question sounds silly or badly grounded.
I am working on a project which makes intense use of Google Guice and
I've seen several places where the class I am working with uses
|
classWhatEver{
@Inject
WhatEver(Provider<A>providerOfA ...){...}
}
|
I do not understand how/what implements the provider as I do not see
any class around my module explicitly implementing the interface.
|
Provider<A>
|
I am pretty sure there is not any.
How does that work ? Are providers synthesised/generated ? If yes I
would like to see where this is done - so I can have a better idea
about how the whole thing works.
Thanks in advance,
Pietro.
--
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
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/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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/03d7f568-d413-c5e6-728b-63e72c6e212f%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
c***@gmail.com
2018-02-12 12:38:05 UTC
Permalink
I was reading that page but I can't find where it explicitly says they are
generated. Would you know where the code that generates them is ?
Post by Stephan Classen
Yes, Providers are generated on the fly by guice.
https://github.com/google/guice/wiki/InjectingProviders
Hi all,
I apologise if my question sounds silly or badly grounded.
I am working on a project which makes intense use of Google Guice and I've
seen several places where the class I am working with uses injected
class WhatEver {
@Inject
WhatEver(Provider<A> providerOfA ...) { ... }
}
I do not understand how/what implements the provider as I do not see any
class around my module explicitly implementing the interface.
Provider<A>
I am pretty sure there is not any.
How does that work ? Are providers synthesised/generated ? If yes I would
like to see where this is done - so I can have a better idea about how the
whole thing works.
Thanks in advance,
Pietro.
--
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
<javascript:>.
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/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/2f4ed289-ed7c-458e-bce3-ba4e64994438%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2018-02-12 12:53:11 UTC
Permalink
There are many different implementations depending on the scope and the
binding.
An incomplete list is:
- InjectorImpl.getProviderOrThrow()
- Scopes.SINGLETON
- ProviderLookup.getProvider()
- Providers.of()
- Providers.gucify()

In the end it doesn't matter which implementation is actually injected.
The main things you need to know is what a provider is good for:
- Delayed injection (because something is expensive to create or only
available in a specific scope)
- Multiple injection (because you need more than one instance off it. If
this is the case think twice if you need DI for this class or rather a
factory)
- Provide your own Provider (if you implement a custom scope)
Post by c***@gmail.com
I was reading that page but I can't find where it explicitly says they
are generated. Would you know where the code that generates them is ?
Yes, Providers are generated on the fly by guice.
https://github.com/google/guice/wiki/InjectingProviders
<https://github.com/google/guice/wiki/InjectingProviders>
Post by c***@gmail.com
Hi all,
I apologise if my question sounds silly or badly grounded.
I am working on a project which makes intense use of Google Guice
and I've seen several places where the class I am working with
|
classWhatEver{
@Inject
WhatEver(Provider<A>providerOfA ...){...}
}
|
I do not understand how/what implements the provider as I do not
see any class around my module explicitly implementing the interface.
|
Provider<A>
|
I am pretty sure there is not any.
How does that work ? Are providers synthesised/generated ? If yes
I would like to see where this is done - so I can have a better
idea about how the whole thing works.
Thanks in advance,
Pietro.
--
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,
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice
<https://groups.google.com/group/google-guice>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
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
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/2f4ed289-ed7c-458e-bce3-ba4e64994438%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/2f4ed289-ed7c-458e-bce3-ba4e64994438%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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/19f31fed-0425-3308-a05c-847f041ec53f%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
c***@gmail.com
2018-02-12 13:17:22 UTC
Permalink
Ah ok, thanks.
Post by Stephan Classen
There are many different implementations depending on the scope and the
binding.
- InjectorImpl.getProviderOrThrow()
- Scopes.SINGLETON
- ProviderLookup.getProvider()
- Providers.of()
- Providers.gucify()
In the end it doesn't matter which implementation is actually injected.
That is actually my main interest, I am digging into the
InjectorImpl.getProviderOrThrow() to see where I get. If you have other
userful links such as the ones you just gave me, feel free!
Post by Stephan Classen
- Delayed injection (because something is expensive to create or only
available in a specific scope)
- Multiple injection (because you need more than one instance off it. If
this is the case think twice if you need DI for this class or rather a
factory)
- Provide your own Provider (if you implement a custom scope)
I was reading that page but I can't find where it explicitly says they are
generated. Would you know where the code that generates them is ?
Post by Stephan Classen
Yes, Providers are generated on the fly by guice.
https://github.com/google/guice/wiki/InjectingProviders
Hi all,
I apologise if my question sounds silly or badly grounded.
I am working on a project which makes intense use of Google Guice and
I've seen several places where the class I am working with uses injected
class WhatEver {
@Inject
WhatEver(Provider<A> providerOfA ...) { ... }
}
I do not understand how/what implements the provider as I do not see any
class around my module explicitly implementing the interface.
Provider<A>
I am pretty sure there is not any.
How does that work ? Are providers synthesised/generated ? If yes I would
like to see where this is done - so I can have a better idea about how the
whole thing works.
Thanks in advance,
Pietro.
--
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
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/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
<javascript:>.
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/2f4ed289-ed7c-458e-bce3-ba4e64994438%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/2f4ed289-ed7c-458e-bce3-ba4e64994438%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/bccbc9af-0ef1-4ef7-b0bf-82c98d4ce948%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...