FYI, there's a class hidden away in
com.google.inject.internal.UniqueAnnotations<http://code.google.com/p/google-guice/source/browse/core/src/com/google/inject/internal/UniqueAnnotations.java>
that
does this (in a slightly cleaner/simpler way).  It's in internal, so not
part of the public API and is subject to change/moving/deletion/etc... but
so many folks use it that it's probably worthwhile promoting it to
c.g.i.util.  Note, though, that it's just a unique *annotation*, not a
unique key.  Key is still a combination of a TypeLiteral & a binding
annotation, as Colin mentioned.  So you'd use something like
Key.get(YourClass.class, UniqueAnnotations.create()) instead of a helper
getUniqueKey(Class) method, which I'd argue is a little more understandable
and keeps the concepts well-separated.

sam

On Mon, Jan 2, 2012 at 1:36 PM, glenviewjeff <[email protected]> wrote:

> Hi Colin:
>
> I'm putting together a little article about designing what I believe to be
> good Guice binding architecture.  It makes heavy use of Gimlet's
> LegProvider for solving the robot legs problem.  I'll probably ask you to
> review it if you don't mind before I post it.
>
> In the meantime, I'm now using code like this to make my bindings more
> readable:
>
>    private static final Key<Boolean> TRUE_KEY =
> getUniqueKey(Dashboard.class);
>
> Where getUniqueKey is defined inside AbstractModuleWithBindingHelpe**rs:
>
>    protected <T> Key<T> getUniqueKey(Class<T> superClass) {
>       Key<T> key =
>        Key.get(superClass, Names.named(UUID.randomUUID().toString()));
>       return key;
>
>    }
>
>
>  --
> 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/-/CqHe6A5yH6cJ.
>
> 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