Mixing injected with passed parameters

53 views
Skip to first unread message

Javier G. Visiedo

unread,
Jul 3, 2017, 9:59:20 AM7/3/17
to google-guice
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?

Stephan Classen

unread,
Jul 3, 2017, 10:07:21 AM7/3/17
to google...@googlegroups.com
--
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.

Reply all
Reply to author
Forward
0 new messages