Binding Property

31 views
Skip to first unread message

Jochen Wiedmann

unread,
Aug 21, 2014, 2:35:03 AM8/21/14
to google...@googlegroups.com


Hi,


suggest the following field:


    private @Driver @Inject Seat seat;


and the following bindings:


    pBinder.bind(Seat.class).toClass(DefaultSeat.class);
    pBinder.bind(Seat.class).annotatedWith(Driver.class).toClass(DriversSeat.class);


What would be the type of seat? I would hope for a DriversSeat, but that assumes a priority of bindings, that I am unaware of. Is there something like that?

Thanks,

Jochen

Thomas Broyer

unread,
Aug 21, 2014, 4:59:08 AM8/21/14
to google...@googlegroups.com
If I'm not mistaken, you'd have an error if you didn't have the second binding: because @Driver is a @BindingAnnotation or @Qualifier, Guice will refuse to inject the field if it hasn't been configured with a binding for "Seat annotated with @Driver" (it won't even inject a Seat instance if Seat is default-instantiable or is annotated with @ImplementedBy or @ProvidedBy).

So there's no need for priorities: the "Seat" key is distinct from the "@Driver Seat" one.

Jochen Wiedmann

unread,
Aug 22, 2014, 6:39:08 AM8/22/14
to google...@googlegroups.com
Thanks for your reply, Thomas. In particular, I wasn't aware of the necessity to use @BindingAnnotation. But, lets assume that the annotation is present on the @Driver class. If so, my example becomes valid. And, indeed, Guice does create an instance of DriversSeat, rather than DefaultSeat.

Jochen



--
You received this message because you are subscribed to a topic in the Google Groups "google-guice" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-guice/bKWvq_HqH0I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/e38aa7a0-3c25-4ca2-86af-33e0641fe6bf%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Our time is just a point along a line that runs forever with no end.
(Al Stewart, Lord Grenville)

Reply all
Reply to author
Forward
0 new messages