This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi guys, Here's the situation. In my ASP.NET MVC app I'm registering a singleton instance of PerRequestUnitOfWorkScope in my DI container (Ninject in this case). The Ninject container hooks the ASP.NET pipeline, and during HttpApplication_End, it attempts to dispose of anything left in the container. Since PerRequestUnitOfWorkScope implements IDisposable, the Dispose() method is being called - however, at this point in the ASP.NET shutdown sequence, the HttpContext is no longer available, so the PerRequestUnitOfWorkScope.HasCurrent property (which is called from Dispose()) throws a NullReferenceException. Since the primary purpose of HasCurrent is to guard access to the Current property, do you have any objection to checking for the existance of HttpContext.Current before accessing it? Thanks, Greg |
|
|
No objection at all. The fix you suggest will be in the next nightly build of LightSpeed 4 (we can backport it to 3 if required, but would prefer you to upgrade to 4 unless there is a compatibility impact). That said, the Dispose method for scopes is broken and should not be relied on for disposal. You still need to dispose scope.Current at the end of each request, making scope.Dispose superfluous and misleading. (I realise it's Ninject calling scope.Dispose, not you -- just saying for anyone else who happens across this thread!) As a handy helper, LightSpeed 4 includes a base controller class which takes care of instantiating scopes when required and disposing units of work automatically at the end of each request -- might be worth checking out since you are using MVC. |
|