Skip to content

Commit

Permalink
Merge pull request dnnsoftware#5788 from bdukes/fix/di-scope-infinite…
Browse files Browse the repository at this point in the history
…-loop

Fix infinite loop on install
  • Loading branch information
david-poindexter authored Aug 9, 2023
2 parents ce0fc4f + 59e877d commit 827790d
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace DotNetNuke.Common.Extensions
{
using System.Collections;
using System.Web;

using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -51,9 +52,10 @@ public static IServiceScope GetScope(this HttpContext httpContext)
/// <returns>A service scope.</returns>
public static IServiceScope GetScope(this HttpContextBase httpContext)
{
if (httpContext.Items.Contains(typeof(IServiceScope)))
var scope = httpContext.Items.GetScope();
if (scope is not null || Globals.DependencyProvider is null)
{
return httpContext.Items[typeof(IServiceScope)] as IServiceScope;
return scope;
}

var scopeLock = new object();
Expand All @@ -64,7 +66,6 @@ public static IServiceScope GetScope(this HttpContextBase httpContext)
return GetScope(httpContext);
}

IServiceScope scope = null;
httpContext.Items.Add(ScopeLockName, scopeLock);
lock (httpContext.Items[ScopeLockName])
{
Expand All @@ -87,9 +88,14 @@ public static IServiceScope GetScope(this HttpContextBase httpContext)
return GetScope(httpContext);
}

private static IServiceScope GetScope(this IDictionary httpContextItems)
{
return httpContextItems[typeof(IServiceScope)] as IServiceScope;
}

private static void DisposeScope(HttpContextBase httpContext)
{
httpContext.GetScope()?.Dispose();
httpContext.Items.GetScope()?.Dispose();
httpContext.ClearScope();
}
}
Expand Down

0 comments on commit 827790d

Please sign in to comment.