Hey guys,

I'm lost while associating Ebean ORM server with a CurrentUser in Ninja 
framework that uses Guice everywhere.
Ebean server is initialized only once during the whole Ninja app start so 
it's a singleton.
So that I can use Ebean's model(entity) annotations @WhoCreated and 
@WhenCreated on my database models I have to give to ebean server an object 
that implements Ebean's simple interface CurrentUserProvider. Obviously in 
this implementation I need to get Ninja's request or session objec to get 
an actual current user ID. These are usually accesible in Ninja controllers 
since one can @Inject them there.

But now how can I "Inject" that session or  request object into CurrentUser 
object if that object is initialized and created during a Ninja app start. 
So during that operation there is not yet any request, session. Since these 
are related with controllers (request cycle) only. Ebean server internally 
does not know anything about Guice (they do not use it).

Simplified example:

class NinjaAppModule extends AbstractModule {
    configure() {
        *CurrentUserProviderImpl userProvider = new 
CurrentUserProviderImpl(properties, injector);*
*        bind(CurrentUserProvider.class).toInstance(userProvider);*

class CurrentUserProviderImpl implements *CurrentUserProvider* {   //* this 
is Ebean's interface that does not anything about Guice*
    Injector injector; 
    CurrentUserProviderImpl(*Injector injector*) {
        this.injector = injector;

    public Long currentUser() {
        RequestSession sess = *injector.getInstance(RequestSession.class);*
        return sess.get("userID");

Yes I know I could somehow use ThreadLocals in my request filter and set 
there userId but how to avoid using ThreadLocal ? Is anything like that 
possible with Guice ??

Thank you

You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to