Discussion:
Mixing injected with passed parameters
Javier G. Visiedo
2017-07-03 13:59:19 UTC
Permalink
Hi,
I wonder if it is possible to mixed injected parameters with user passed
parameters. Let me try to illustrate with an example in scala.

Imagine a class using a remote service. Let's say I would like to inject
some configuration parameters for the service, such as the end point VIP
and the service path. At the same time I want to be able to instantiate
this object with some specific credentials.

// Config class in module
@Provides
@Singleton
def provideClientConf(injector: Injector): ClientConf = {
// some code reading conf
val vip = //read the vip
val servPath = //read the path

ClientConf(vip, servPath)
}

//The client class that injects the config
class Client @Inject(myConf: ClientConf, ClientID: String) = ???

Now, I would like to inject serviceVIP, and servicePath, but pass the
ClientID

val myClient = new Client ("myClientID")

Is that possible in Guice?
--
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/a930d63b-d103-429d-8761-a67e2ca24794%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-07-03 14:07:16 UTC
Permalink
look at:

https://github.com/google/guice/wiki/AssistedInject
Post by Javier G. Visiedo
Hi,
I wonder if it is possible to mixed injected parameters with user
passed parameters. Let me try to illustrate with an example in scala.
Imagine a class using a remote service. Let's say I would like to
inject some configuration parameters for the service, such as the end
point VIP and the service path. At the same time I want to be able to
instantiate this object with some specific credentials.
// Config class in module
@Provides
@Singleton
def provideClientConf(injector: Injector): ClientConf = {
// some code reading conf
val vip = //read the vip
val servPath = //read the path
ClientConf(vip, servPath)
}
//The client class that injects the config
Now, I would like to inject serviceVIP, and servicePath, but pass the
ClientID
val myClient = new Client ("myClientID")
Is that possible in Guice?
--
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/a930d63b-d103-429d-8761-a67e2ca24794%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/a930d63b-d103-429d-8761-a67e2ca24794%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/c5518015-961d-0031-7ea6-f175aae17b43%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Loading...