From 3614cdb965f9ef4e2e74b11d43d0689706de0d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C3=A7=20Garc=C3=ADa=20Alt=C3=A9s?= Date: Mon, 9 Feb 2015 13:14:49 +0000 Subject: [PATCH] Avoid exceptions disposing the dependency scope. When the Dispose method of the StructureMapDependencyScope is called, an exception is thrown trying to access to System.Web.HttpContext.Current. Checking the value before using it will avoid this exception. --- .../StructureMapDependencyScope.cs.pp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/content/DependencyResolution/StructureMapDependencyScope.cs.pp b/content/DependencyResolution/StructureMapDependencyScope.cs.pp index a807999..c46e5cc 100644 --- a/content/DependencyResolution/StructureMapDependencyScope.cs.pp +++ b/content/DependencyResolution/StructureMapDependencyScope.cs.pp @@ -64,11 +64,13 @@ #region Properties private HttpContextBase HttpContext { - get { - var ctx = Container.TryGetInstance(); - return ctx ?? new HttpContextWrapper(System.Web.HttpContext.Current); - } - } + get { + return (System.Web.HttpContext.Current == null + ? null + : (Container.TryGetInstance() ?? + new HttpContextWrapper(System.Web.HttpContext.Current))); + } + } #endregion