Hi there,
I was wondering if there is a way to specify bindings solely via
annotations.
Specifically, I'd like to be able to do something like this...
class Service implements ServiceInterface {
Service() {
}
}
class Decorator1 implements ServiceInterface {
@Inject
Decorator1(@DefaultsTo(Service.class) ServiceInterface service) {
}
}
class Decorator2 implements ServiceInterface {
@Inject
Decorator2(@DefaultsTo(Decorator1.class) ServiceInterface service) {
}
}
...without any additional code in the module's configuration method.
I realize that I could create my own binding annotations or use @Named.
Yet, this would mean that I had to (a) create the binding annotations and
(b) still specify the bindings in the module's configuration method. This
approach seems like unnecessary duplication to me, since it would be easier
to just specify the requested default implementation in the annotation
itself.
In this particular case, it would be sufficient if I could specify bindings
in the configuration method only for special cases (which would override
the hypothetical @DefaultsTo annotation) and otherwise go with the default
implementation specified by @DefaultsTo.
So I'm wondering, is there any built-in way to do this (some Guice
annotation that I'm missing) -- or would it be necessary to take a
different route?
Many thanks in advance
--
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/-/srIwwp5-G_YJ.
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.