Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lock to scoped burdens to ensure only one instance is created per scope #547

Merged
merged 8 commits into from
Sep 15, 2020
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net461;net471;net48</TargetFrameworks>
jonorossi marked this conversation as resolved.
Show resolved Hide resolved

<IsPackable>false</IsPackable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class ExtensionContainerScope : ILifetimeScope, IDisposable
protected static readonly AsyncLocal<ExtensionContainerScope> current = new AsyncLocal<ExtensionContainerScope>();
private readonly ExtensionContainerScope parent;
private readonly IScopeCache scopeCache;

protected ExtensionContainerScope(ExtensionContainerScope parent)
{
scopeCache = new ScopeCache();
Expand Down Expand Up @@ -69,15 +69,14 @@ public Burden GetCachedInstance(ComponentModel model, ScopedInstanceActivationCa
scopeCache[burden] = burden;
jonorossi marked this conversation as resolved.
Show resolved Hide resolved
return burden;
}
else
lock (scopeCache)
{
var burden = scopeCache[model];
if (burden == null)
{
scopeCache[model] = burden = createInstance((_) => {});
}

return burden;
return burden;
}
}

Expand Down