2010/1/26 Esko Luontola <[email protected]> > On Jan 26, 2:28 am, Clinton Begin <[email protected]> wrote: > > Let your community speak for itself, as I'm sure it will. ;-) > > Makes sense. > > Would you still please say on this mailing list, that what were the > design decisions that lead to the requirement of @Inject? There are > quite many frameworks which have gone the other way, that they inject > constructors without any annotations. What are the pros and cons of > either approach? >
FYI, from http://code.google.com/p/google-guice/wiki/Injections "If your class has no @Inject-annotated constructor, Guice will use a public, no-arguments constructor if it exists. Prefer the annotation, which documents that the type participates in dependency injection." see also top part of http://code.google.com/p/google-guice/wiki/InjectionPoints The original decision IIRC was about eliminating surprises that could happen say if someone added another constructor to an existing class - would the new or the old constructor be used? Marking the constructor to be used with @Inject avoids any confusion: http://groups.google.com/group/google-guice/browse_thread/thread/2a252b1a3f7b3779 As a convenience, Guice will use the default constructor if it exists and there are no @Inject annotated constructors - this at least is unambiguous compared to other suggestions, such as choosing the constructor with the most parameters. Also note that Guice trunk lets you bind to a specific constructor without having to use @Inject by defining a constructor binding to the reflected Constructor instance: http://code.google.com/p/google-guice/wiki/ToConstructorBindings HTH It would even be useful to have the motivation for requiring @Inject > to read in the web site's FAQ. > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > -- Cheers, Stuart -- You received this message because you are subscribed to the Google Groups "google-guice" group. 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.
