For the sake of argument let's say that I want my scope to be tied to objects created in a certain method buried deep down in my infrastructure. This method may be re-entered in the same Thread, and I want another "scope" to be started upon re-entrance. Think of a Swing app: things happen on and off the Event Dispatch Thread, and I don't want Guice and my Scope deciding whether or not to reuse an object based on the injection request occurring on EDT or not.
I understand that the Servlet model is predicated on things being Thread-contained but that simply isn't the case for a Swing app where there's lots of Thread hopping going on. -Russ On Wed, Mar 24, 2010 at 5:02 PM, Max Bowsher <[email protected]> wrote: > On 24/03/10 18:47, Russ wrote: > >> It seems that all Guice's out-of-the-box Scope implementations are >> inherently Thread-based (or ignore Threads entirely): >> >> Scopes.SINGLETON and Scopes.NO_SCOPE ignore Threads and are the edge >> cases: global scope and no scope. >> >> ServletScopes.REQUEST and ServletScopes.SESSION ultimately depend on >> retrieving scoped objects from a ThreadLocal<Context>. The retrieved >> Context holds a reference to the HttpServletRequest that holds a >> reference to the scoped objects stored as named attributes (where name >> is derived from com.google.inject.Key). >> >> Class SimpleScope from the custom scope Guice wiki also provides a per- >> Thread implementation using a ThreadLocal<Map<Key<?>, Object>> member >> variable. >> >> With that preamble, my question is this: how does one go about >> creating a non-Thread-based Scope? It seems that something that I can >> use to look up a Map<Key<?>, Object> is missing, as the only things >> passed in to Scope.scope() are a Key<T> and a Provider<T>. >> > > > On what do you wish to base your Scope, if not on Thread identity? > > > Max. > > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
