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

SingletonLifestyleManager

Only one instance is created first time an instance of the component is requested, and it is then reused for all subseque.
using Castle.Core.Internal; using Castle.MicroKernel.Context; using System; namespace Castle.MicroKernel.Lifestyle { [Serializable] public class SingletonLifestyleManager : AbstractLifestyleManager, IContextLifestyleManager { private readonly ThreadSafeInit init = new ThreadSafeInit(); private Burden cachedBurden; public override void Dispose() { Burden burden = cachedBurden; if (burden != null) { burden.Release(); cachedBurden = null; } } public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { if (cachedBurden == null) { bool flag = false; try { flag = init.ExecuteThreadSafeOnce(); if (cachedBurden == null) { Burden burden = cachedBurden = CreateInstance(context, true); Track(burden, releasePolicy); return burden.Instance; } return cachedBurden.Instance; } finally { if (flag) init.EndThreadSafeOnceSection(); } } return cachedBurden.Instance; } public object GetContextInstance(CreationContext context) { return context.GetContextualProperty("castle.component-activator-instance"); } } }