using Connected.Data.Storage; using Connected.Entities.Storage; namespace Connected.Data.Sql; internal abstract class DatabaseCommand : IStorageCommand { protected DatabaseCommand(IStorageOperation operation, IStorageConnection connection) { Connection = connection; Operation = operation; } protected bool IsDisposed { get; private set; } public IStorageOperation Operation { get; } public IStorageConnection? Connection { get; protected set; } protected virtual async ValueTask DisposeAsync(bool disposing) { if (!IsDisposed) { if (disposing) { Connection = null; await OnDisposingAsync(); } IsDisposed = true; } } protected virtual async ValueTask OnDisposingAsync() { await ValueTask.CompletedTask; } protected virtual void OnDisposing() { } public async ValueTask DisposeAsync() { await DisposeAsync(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!IsDisposed) { if (disposing) { Connection = null; OnDisposing(); } IsDisposed = true; } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } }