Re: Optional dependencies and default values

47 views
Skip to first unread message

Stephan Classen

unread,
Jun 27, 2014, 4:48:23 PM6/27/14
to google...@googlegroups.com

Do you create a new injector (or childinjector) for every request?

Am 27.06.2014 22:02 schrieb Edgar Espina <espina...@gmail.com>:
Hi,

 I'm using Guice to inject HTTP Request parameters (I'm not using guice-servlet) and I will like to do things like:

public class Command {
  public Command(@Named("name") String name) {
  }
}

 Here "name" is an HTTP parameter and I'm able to bind it when present.

 The problem (of course) is when that parameter isn't present or sent and want to have a default value for it.

 I know isn't possible to inject something without a binding and it's OK. So what I'm asking here is feedback on how to deal with this? and/or an alternate solution?

Thanks,

edgar

--
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/4a16405b-e29f-4c1b-820c-7f755bd79b77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Edgar Espina

unread,
Jun 27, 2014, 4:50:50 PM6/27/14
to google...@googlegroups.com
child injector per request

Tim Boudreau

unread,
Jun 29, 2014, 5:20:44 AM6/29/14
to google...@googlegroups.com
On Friday, June 27, 2014 4:50:50 PM UTC-4, Edgar Espina wrote:
child injector per request

As recently discussed in another thread, a custom scope will accomplish that with less overhead.

-Tim 
Reply all
Reply to author
Forward
0 new messages