And just for completeness, if you're not comfortable with strings as keys
for your binding annotations, you can also use real annotations, which adds
type safety (no risks of making a typo) and makes it easier to immediately
find occurrences of these bindings from your IDE.


-- 
Cédric




On Mon, Dec 17, 2012 at 7:13 AM, Thomas Broyer <[email protected]> wrote:

>
>
> On Monday, December 17, 2012 3:52:51 PM UTC+1, Dirk Nimerem wrote:
>>
>> Hello Moandji,
>>
>> could you please make an example how to specifiy a binding via annotation
>> for this?
>>
>> Any other class should use the CachedFileReader for an IFileReader, only
>> the CachedFileReader itself should use the basic FileReader.
>>
>
> You know that the CachedFileReader's dependency on IFileReader is special,
> so annotate it in the constructor.
>
> Simple example here with the @Named annotation:
>
> @Inject CachedFileReader(@Named("non_cached") IFileReader fileReader) { … }
>
> then:
>
> // CachedFileReader uses the basic FileReader:
>
> bind(IFileReader.class).annotatedWith(Names.named("non_cached")).to(FileReader.class);
> // Every other class should be given the CachedFileReader:
> bind(IFileReader.class).to(CachedFileReader.class);
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-guice/-/JFnMdRCakToJ.
>
> 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?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" 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?hl=en.

Reply via email to