diff --git a/src/Pure.DI.Core/Components/Api.g.cs b/src/Pure.DI.Core/Components/Api.g.cs index b05aa74ec..3b5293a17 100644 --- a/src/Pure.DI.Core/Components/Api.g.cs +++ b/src/Pure.DI.Core/Components/Api.g.cs @@ -1243,26 +1243,37 @@ internal interface IOwned #endif internal sealed partial class Owned : global::System.Collections.Generic.List, global::Pure.DI.IOwned { + private volatile bool _isDisposed; + /// public void Dispose() { - for (var i = Count - 1; i >= 0; i--) + if (_isDisposed) + { + return; + } + + _isDisposed = true; + try { - switch (this[i]) + for (var i = Count - 1; i >= 0; i--) { - case global::Pure.DI.IOwned _: - break; + switch (this[i]) + { + case global::Pure.DI.IOwned _: + break; - case global::System.IDisposable disposableInstance: - try - { - disposableInstance.Dispose(); - } - catch (global::System.Exception exception) - { - OnDisposeException(disposableInstance, exception); - } - break; + case global::System.IDisposable disposableInstance: + try + { + disposableInstance.Dispose(); + } + catch (global::System.Exception exception) + { + OnDisposeException(disposableInstance, exception); + } + + break; #if NETCOREAPP3_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER case global::System.IAsyncDisposable asyncDisposableInstance: @@ -1280,46 +1291,64 @@ public void Dispose() } break; #endif + } } } + finally + { + Clear(); + } } #if NETCOREAPP3_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER /// public async global::System.Threading.Tasks.ValueTask DisposeAsync() { - for (var i = Count - 1; i >= 0; i--) + if (_isDisposed) { - switch (this[i]) + return; + } + + _isDisposed = true; + try + { + for (var i = Count - 1; i >= 0; i--) { - case global::Pure.DI.IOwned _: - break; + switch (this[i]) + { + case global::Pure.DI.IOwned _: + break; - case global::System.IAsyncDisposable asyncDisposableInstance: - try - { - await asyncDisposableInstance.DisposeAsync(); - } - catch (global::System.Exception exception) - { - OnDisposeAsyncException(asyncDisposableInstance, exception); - } - break; + case global::System.IAsyncDisposable asyncDisposableInstance: + try + { + await asyncDisposableInstance.DisposeAsync(); + } + catch (global::System.Exception exception) + { + OnDisposeAsyncException(asyncDisposableInstance, exception); + } + break; - case global::System.IDisposable disposableInstance: - try - { - disposableInstance.Dispose(); - } - catch (global::System.Exception exception) - { - OnDisposeException(disposableInstance, exception); - } - break; + case global::System.IDisposable disposableInstance: + try + { + disposableInstance.Dispose(); + } + catch (global::System.Exception exception) + { + OnDisposeException(disposableInstance, exception); + } + break; + } } } + finally + { + Clear(); + } } -#endif +#endif ///