I haven't started implementing the custom scope yet so I can't really
comment on how to enter/exit a scope. What you propose sounds
reasonable, using a Callable, and finally block to exit.



On Feb 24, 2:36 pm, Fred Faber <[email protected]> wrote:
> How would you enter such a scope?  Can you complement such an entry point
> with an exit point?
>
> A typical way to do this is to run your scoped code as a Callable, and exit
> the scope in a finally{} block.
>
> On Thu, Feb 24, 2011 at 3:34 PM, scott <[email protected]> wrote:
> > Thanks for the response. After I submitted the post, I found this one
> > that looks to be along the same lines:
>
> >http://groups.google.com/group/google-guice/browse_thread/thread/ec5d...
>
> > I'm considering writing a custom scope, and might build something like
> > this into it. I was really hoping that built-in Guice scopes (like
> > RequestScoped) had some mechanism to accomplish this, but like you, I
> > don't see anything to lead me to believe that this feature is there.
>
> > My planned approach is to use Guice AOP, and implement the cleanup in
> > a MethodInterceptor, after the business logic is called. It's not the
> > cleanest approach because I'm now dependent on an annotation being put
> > on the logic to do the cleanup, but its the best I've come up with so
> > far.
>
> > On Feb 23, 11:59 am, Fred Faber <[email protected]> wrote:
> > > This is something that will be dependent on the scope you use.  None of
> > the
> > > Scopes bundled with Guice proper include such a feature afaik.
>
> > > But on that note, I'm about to build it into a custom scope I use, and so
> > I
> > > do think the idea has wheels.
>
> > > Fred
>
> > > On Wed, Feb 23, 2011 at 1:48 AM, scott <[email protected]> wrote:
> > > > I was just wondering if there is any way to implement a callback to
> > > > perform some logic when an object goes out of "Scope" ? For example, I
> > > > have a Request scoped @Provides method, that creats an object and does
> > > > some initialization on it, I need a way to do some cleanup when the
> > > > scope is exiting. -thanks
>
> > > > --
> > > > 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.
>
> > --
> > 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.

-- 
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.

Reply via email to