frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Injector.getInstance() broken for annotation instances #125

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When I create my injector, I refer to the annotation type statically:
  bind(...).to(...).annotatedWith(LoginName.class);

But when I annotate my injection points, the annotation as an instance:
  @LoginName String loginName;
For example, if I refer to this annotation at runtime, I get the annotation
instance instead of the annotation type.

Guice elegantly behaves as if annotation instances and annotation types are
interchangeable, and I enjoy this behaviour.

Unfortunately, this isn't the case for Keys, which means I cannot fetch a
binding at runtime using the annotation instance if it was bound with the
annotation type.

I can think of two possible fixes:
 - make it so Keys are equal if one is an annotation type and the other is
the default value of that annotation
 - make Injector.getBinding() work extra hard if an annotation instance is
passed in, in which case it would also try the annotation type.

Original issue reported on code.google.com by limpbizkit on 3 Jul 2007 at 12:26

Attachments:

GoogleCodeExporter commented 9 years ago
It's silly that we could have two keys, Key.get(Foo.class, 
MarkerAnnotation.class) and Key.get(Foo.class, new 
MarkerAnnotationImpl.class) that are non-equal. We should fix this for 2.0.

Original comment by limpbizkit on 8 Jun 2008 at 11:34

GoogleCodeExporter commented 9 years ago
Fixed.

Original comment by limpbizkit on 25 Jun 2008 at 7:11