"to no real benefit"
I think the benefit is clarity, and avoiding a class of error. Given
that you do want to differentiate between certain classes of constructor
on the basis of visibility, you do want this benefit, it's just that you
want it on the basis of a convention, rather than an annotation. That's
cool, but I would humbly suggest that the annotation was created for
just such a purpose - to indicate intent, and the restriction was
designed to enforce the intent - that this is an "injectable" class.
So... I guess it's an opinion, but I certainly don't feel that it's "to
no real benefit" even if that benefit is "merely" executable
documentation of intent and code-clarity.
Just my 10,000 satoshis,
Christian.
On 27 Dec 2013, at 14:34, Sam Berlin wrote:
I don't know if there's any way to do exactly what you'd like.
requireAtInjectOnConstructors works the way it does because it's
intended
to prevent accidentally creating things that aren't meant to be
injected
(but do have no-args cxtors). Accidentally constructing these kinds
of
things can happen whether or not the implementation is public,
package-private or private... so that's the logic behind the check
right
now.
We generally use requireAtInjectOnConstructors internally, and folks
just
sprinkle no-args constructors with @Inject where necessary. Note that
if
you use bind(..).toConstructor(cxtor), that doesn't require the
@Inject --
so if you have some kind of framework creating bindings for you, you
could
potentially use that.
sam
On Tue, Dec 17, 2013 at 11:04 PM, Tavian Barnes
<[email protected]>wrote:
I'd like to enforce a restriction like Guice
4's requireAtInjectOnConstructors() but slightly weaker: any class
with
less-than-public effective visibility may have a non-annotated,
no-arguments constructor. This is because I have a lot of
package-private
implementation classes, and it's a pity to have to change
class ThingImpl implements Thing {
...
}
into
class ThingImpl implements Thing {
@Inject
ThingImpl() {
}
...
}
for all of them, with no real benefit. On the other hand, it is
helpful
to be notified of public classes which accidentally have a public,
non-annotated constructor.
It seems this is almost possible with TypeListener, except it will
also
trigger on requestInjection()/injectMembers(). Any ideas on how I
could
do this?
--
You received this message because you are subscribed to the Google
Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it,
send an
email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.
Christian Gruber :: Google, Inc. :: Java Core Libraries :: Dependency
Injection
email: [email protected] :::: mobile: +1 (646) 807-9839
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.