Revision: 1397
Author: sberlin
Date: Sat Nov 20 18:27:40 2010
Log: Edited wiki page FrequentlyAskedQuestions through web user interface.
http://code.google.com/p/google-guice/source/detail?r=1397
Modified:
/wiki/FrequentlyAskedQuestions.wiki
=======================================
--- /wiki/FrequentlyAskedQuestions.wiki Thu Jul 16 11:08:26 2009
+++ /wiki/FrequentlyAskedQuestions.wiki Sat Nov 20 18:27:40 2010
@@ -11,7 +11,7 @@
@BindingAnnotation
public @interface FooServerAddress {}
}}}
-Bind the annotation to its value value in your module:
+Bind the annotation to its value in your module:
{{{
public class FooModule {
private final String fooServerAddress;
@@ -127,12 +127,19 @@
}
}
}}}
-You need to use
[http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/TypeLiteral.html
TypeLiteral] to create the binding. `TypeLiteral` is a special class that
allows you to specify a full parameterized type.
+You can use a
[http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/TypeLiteral.html
TypeLiteral] to create the binding. `TypeLiteral` is a special class that
allows you to specify a full parameterized type.
{{{
@Override public void configure() {
bind(new TypeLiteral<List<String>>() {}).toInstance(new
ArrayList<String>());
}
}}}
+
+Alternately, you can use an @Provides method.
+{{{
+ @Provides List<String> providesListOfString() {
+ return new ArrayList<String>();
+ }
+}}}
===How can I inject optional parameters into a constructor?==
Neither constructors nor `...@provides` methods support optional injection.
To work-around this, you can create an inner class that holds the optional
value:
@@ -165,6 +172,15 @@
}
}
}}}
+
+Another option is to use Binder.getProvider and pass the dependency in the
constructor of the interceptor.
+{{{
+public class NotOnWeekendsModule extends AbstractModule {
+ protected void configure() {
+ bindInterceptor(any(), annotatedWith(NotOnWeekends.class), new
WeekendBlocker(getProvider(Calendar.class)));
+ }
+}
+}}}
===How can I get other questions answered?===
Please post to the [http://groups.google.com/group/google-guice
google-guice] discussion group.
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.