Skip to content

Conversation

@huguesb
Copy link

@huguesb huguesb commented Dec 18, 2014

If a binding exists for the Scoping class, use it whenever no
explicit scope is provided.

NB: Only instance bindings are supported at this time.

If a binding exists for the Scoping class, use it whenever no
explicit scope is provided.

NB: Only instance bindings are supported at this time.
@googlebot
Copy link

Thanks for your pull request.

It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA) at https://cla.developers.google.com/.

If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check the information on your CLA or see this help article on setting the email on your git commits.

Once you've done that, please reply here to let us know. If you signed the CLA as a corporation, please let us know the company's name.

@sameb
Copy link
Member

sameb commented Dec 18, 2014

Thanks for this PR, however I don't think we want to let folks change the default scope. Also, Scoping is an internal class that users should not be using.

@sameb sameb closed this Dec 18, 2014
@huguesb
Copy link
Author

huguesb commented Dec 19, 2014

I understand the concern about the use of Scoping. Is there any chance a different patch could be accepted?

We have a sizable code base where, for various historical and technical reasons, most injected classes are singletons. Having to annotate each and every class is tedious and error-prone so we've been using a custom build of guice with this patch for more than two years and I hoped the 4.0 release window would be a good opportunity to switch back to a vanilla build.

@sameb
Copy link
Member

sameb commented Dec 19, 2014

Allowing folks to easily change the default scope makes using Guice unpredictable -- modules & code would be written for one paradigm & then accidentally used in another.

Keep in mind https://github.com/google/guice/wiki/Scopes#choosing-a-scope -- "If the object is stateless and inexpensive to create, scoping is unnecessary. Leave the binding unscoped and Guice will create new instances as they're required." ... It's likely that you don't really need all your classes as singletons, so consider re-evaluating that. Only stateful objects or objects that are expensive to create (or created so many times as to be a perf problem) really need to be singletons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants