From 36ac91051002a008d533503a875f481aa6a98064 Mon Sep 17 00:00:00 2001 From: Rik Svendsen Rose Date: Thu, 10 Dec 2020 09:06:31 +0100 Subject: [PATCH] Add check that the disposing scope is current, before changing the parent. #563 --- .../Scope/ExtensionContainerScope.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs b/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs index b2d2fa7d36..cbdf977e5c 100644 --- a/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs +++ b/src/Castle.Windsor.Extensions.DependencyInjection/Scope/ExtensionContainerScope.cs @@ -51,12 +51,15 @@ internal static ExtensionContainerScope BeginScope() public void Dispose() { + if (current.Value == this) + { + current.Value = parent; + } + if (scopeCache is IDisposable disposableCache) { disposableCache.Dispose(); } - - current.Value = parent; } public Burden GetCachedInstance(ComponentModel model, ScopedInstanceActivationCallback createInstance)