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.
