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

DefaultLifetimeScope

using Castle.Core; using System; namespace Castle.MicroKernel.Lifestyle.Scoped { public class DefaultLifetimeScope : ILifetimeScope, IDisposable { private static readonly Action<Burden> emptyOnAfterCreated = delegate { }; private readonly Action<Burden> onAfterCreated; private readonly IScopeCache scopeCache; public DefaultLifetimeScope(IScopeCache scopeCache = null, Action<Burden> onAfterCreated = null) { this.scopeCache = (scopeCache ?? new ScopeCache()); this.onAfterCreated = (onAfterCreated ?? emptyOnAfterCreated); } public void Dispose() { (scopeCache as IDisposable)?.Dispose(); } public Burden GetCachedInstance(ComponentModel model, ScopedInstanceActivationCallback createInstance) { Burden burden = scopeCache[model]; if (burden == null) burden = (scopeCache[model] = createInstance(onAfterCreated)); return burden; } } }