Skip to content

How to cache a singleton instance in a subscope of a binding? #434

@bernard-crnkovic

Description

@bernard-crnkovic

Suppose I am building a Web server. I tried to organize my scopes as such:

AppScope -> SessionScope -> RequestScope -> MyScope

How would I go about binding singleton instances to last scope and not to the scope where they were installed?
My motivation for such approach is performance. Suppose there are a lot of bindings in RequestScope that need to be installed (say thousands), but very few of them are ever used. It would be very expensive to install those bindings on every request when they are not needed. If I could just install them once but instantiate them in subscope that would be great!

So I'd like to resolve those few instances and cache them during request in MyScope. However, current behavior is that RequestScope caches them and I am stuck. I tried playing with supportScopeAnnotations without luck.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions