inject factory created object?

49 views
Skip to first unread message

klc

unread,
May 19, 2015, 6:43:41 AM5/19/15
to google...@googlegroups.com
Hi all I have a servlet app that read a configuration file on settings of different services (>1000), like auto commit.
And when a request come in, it use this configuration to create a per request context object for services to use.

Now for the context object i can use assisted inject to create them by factory. but how do I re-inject them in services, instead of passing them explicitly?

Stephan Classen

unread,
May 19, 2015, 7:03:10 AM5/19/15
to google...@googlegroups.com
You can bind the object in request scope.
--
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...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/c39f19b4-8830-4c3b-89ad-e3e0e4680c06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

klc

unread,
May 19, 2015, 7:46:34 AM5/19/15
to google...@googlegroups.com
Would this need the injector?

klc

unread,
May 19, 2015, 11:19:00 PM5/19/15
to google...@googlegroups.com
I think i have to be more specific for a solid advice :)

I guess the thing I don't understnad is how to transit from singleton servlet to request scoped objects
for eg I have a singleton servlet to process a request, to use request scoped object i have to use a provider class. (https://github.com/google/guice/wiki/Scopes#scopes-and-concurrency)

but the provider class need inject of request scope object as well (eg httpservletrequest), ie:

@Singleton
public class Servlethandler ... {
    @Inject
    Provider<RequestScopeObj> obj
}

public class RSprovider {
    @Inject
    public RSprovider(HttpServletRequest req) {...}
}

As servlet handler is singleton, i don't understand how to request scope object would work.
Reply all
Reply to author
Forward
0 new messages