Reputation: 15953
I'd like to use a dependency injection framework.
During my evaluation I came to the conclusion that Google Guice seems to fit best for my demands.
However, some questions came into my mind:
Imagine a web application in which a user can have independent windows within a http session. The Session
scope is too general while the Request
scope is too narrow for me.
Is there a scope which will help me out? (something I would call "window
" or "controller instance
" scope)
Are there any pitfalls writing a custom scope?
Our web application and several stand alone console applications are using the same classes. I am facing the problem that the scope of a class depends on the application type which is only known at runtime.
E.g. in a standalone application the scope would be "No-Scope" or "per-Thread Scope", while in a web application it would be bound to a Session
/"window
".
How to solve this problem?
Upvotes: 2
Views: 752
Reputation: 2116
You can use scope with application context handlers which help in deciding how your scoping logic works. Then using the same custom scope you can control how the objects get created at runtime.
Upvotes: 1
Reputation: 13222
To answer 3. use different modules for your versions, and set the scopes there.
bind(Grill.class).to(Applebees.class).in(Scopes.SINGLETON);
Upvotes: 2
Reputation: 64622
Upvotes: 2