<PackageReference Include="Castle.Windsor" Version="3.0.0.2001" />

ScopeCache

using Castle.Core.Internal; using System; using System.Collections.Generic; using System.Linq; namespace Castle.MicroKernel.Lifestyle.Scoped { public class ScopeCache : IScopeCache, IDisposable { private readonly IDictionary<object, Burden> cache = new Dictionary<object, Burden>(); public Burden this[object id] { get { cache.TryGetValue(id, out Burden value); return value; } set { cache.Add(id, value); } } public void Dispose() { CollectionExtensions.ForEach<Burden>(cache.Values.Reverse(), (Action<Burden>)delegate(Burden b) { b.Release(); }); cache.Clear(); } } }