dongfo / autofac

Automatically exported from code.google.com/p/autofac
0 stars 0 forks source link

Expose IsDisposed for ILifetimeScope #334

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Now that the behavior for disposed lifetime scopes has been tightened up, it 
would be nice to know the disposed state of a scope for fallback purposes.

Exposing the IsDisposed property would be appreciated.

Changes implemented here 
http://code.google.com/r/nicaog-autofac/source/detail?r=7875ecef06f22ebef60ec704
45033353fed299cf
and here
http://code.google.com/r/nicaog-autofac/source/detail?r=45fb0a6c1027641255ea87cf
4e1d78f9c9315ed3

Original issue reported on code.google.com by nic...@gmail.com on 4 Jul 2011 at 5:17

GoogleCodeExporter commented 8 years ago
Hi - I'm not sure from your email what scenarios would be supported by this 
property. Can you please give an indication of how IsDisposed would be used in 
a typical application?

Thanks very much for the suggestion.

Nick

Original comment by nicholas...@gmail.com on 16 Aug 2011 at 8:35

GoogleCodeExporter commented 8 years ago
Maybe resolution to issue 299 would resolve his request.

If CheckNotDisposed() in ResolveComponent 
is changed to something like
if (IsDisposed)
   return _parent.ResolveComponent(registration, parameters);

Exposing IsDisposed smells like a bad design to me.

Regards,
Rikard

Original comment by rikard.p...@gmail.com on 6 Sep 2011 at 7:48

GoogleCodeExporter commented 8 years ago
Thanks for the idea. I think without having concrete scenarios there is too 
much guesswork to take action on this. Will close for now, but anyone with more 
details can always feel free to reopen. Cheers!

Original comment by nicholas...@gmail.com on 6 Sep 2011 at 1:12

GoogleCodeExporter commented 8 years ago
Sorry to wait this long to comment, but I had to get back to the code that 
prompted me to post this.

The reason for this was that I have been using the common service locator in my 
logging system. I've adjusted the service locator to look first in the current 
HTTP context for a lifetime and if not fall back to the application scope.  The 
problem is that Autofac disposes its' lifetimes before the http context ends 
and so certain logging operations were getting routed to a disposed lifetime 
scope.

This is perhaps a bit of a design flaw on my part and I am going to try to work 
around it. 

Original comment by nic...@gmail.com on 27 Sep 2011 at 5:48