google / guice

Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 11 and above, brought to you by Google.
https://github.com/google/guice
Apache License 2.0
12.51k stars 1.67k forks source link

Depending on a narrower scope is not an error #1310

Open ivangreene opened 4 years ago

ivangreene commented 4 years ago

This documentation page states:

It is an error to depend on an object in a narrower scope

However, this is not enforced, so not truly an error. An exception should either be thrown when injecting an object with an object of a narrower scope, or the documentation should be revised to reflect that this will merely cause unintended results but is not an 'error'.

ivangreene commented 4 years ago

For now, I wrote a workaround for us to ensure that dependents of a class do not have any scope: https://gist.github.com/ivangreene/2f2d782770e839945ec3ff42a5f3f939