internal override object CreateInstance(Type interfaceType, ComponentContainer componentContainer, Action <string> progressCallback, ComponentDescriptor[] resolveStack) { //We need to seperate locking on the instance reference collection (new wrapper) and setting/add-ref-ing because otherwise we can dead-lock SingletonComponentInstance.instanceLock.Wait(); bool MustCreate = false; try { try { if (this.InstanceReference == null) { this.InstanceReference = new SingletonInstanceWrapper(); MustCreate = true; } this.InstanceReference.Lock.Wait(); } finally { SingletonComponentInstance.instanceLock.Release(); } if (MustCreate) { this.InstanceReference.SetInstance(this.DoCreateInstance(interfaceType, componentContainer, progressCallback, resolveStack)); } return(this.InstanceReference.AddReference(componentContainer)); } finally { this.InstanceReference?.Lock.Release(); } }
internal override void Dispose(ComponentContainer componentContainer) { if (this.InstanceReference != null && this.InstanceReference.ReleaseReference(componentContainer)) { (this.InstanceReference.Target as IDisposable)?.Dispose(); this.InstanceReference = null; Debug.WriteLine($"Disposing singleton component instance {this.Name}"); base.Dispose(componentContainer); } }