allow hierarchical scopes
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 1.7k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
I have the problem that for my [Vaadin-addon for guice](https://github.com/berndhopp/guice), there are scopes that are 'hierarchical', in the sense that there is a hierarchy of scopes with 'Singleton' at the top, 'VaadinSessionScope' below that, then 'UIScope' and then 'Prototype'. Objects in VaadinSessionScope have the scope of a vaadin-session, which is basically a http-session, UI-scoped objects have the scope of their UI, (which is basically a browser-tab). Now it is very easy to make the mistake to inject objects from a lower scope, e.g. VaadinSessionScope, to a higher level scope, e.g. Singleton. In that case, the singleton-object will obtain a reference to an object that belongs to the vaadin-session, which is certainly not what the developer intended and leads to all kinds of bugs, including revealing of sensitive information of other users in the worst case. So my proposal is to allow for hierarchies in scopes, with a simple call 'under()' like:
bindScope(VaadinSessionScope.class).to(VaadinSessionScoper.class).under(Singleton.class);
bindScope(UIScope.class).to(UIScoper.class).under(VaadinSessionScope.class);
Guice should then throw an exception when a UIScope-object is to be injected into a VaadinSessionScope-object. It is however allowed to inject Providers of UIScope-objects into VaadinSessionScope-objects, so the VaadinSessionScope-object can obtain a reference to the 'current' UIScoped-object. Does that make sense?
This scenario can probably be translated to all frameworks that handle user-based scopes , because these scopes all introduce a hierarchy of some kind.
Contributor guide
Assessment
This issue has not been assessed yet.