From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 Aging.Infrastructure/Core/OperationLease.cs |   82 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/Aging.Infrastructure/Core/OperationLease.cs b/Aging.Infrastructure/Core/OperationLease.cs
new file mode 100644
index 0000000..3d41e55
--- /dev/null
+++ b/Aging.Infrastructure/Core/OperationLease.cs
@@ -0,0 +1,82 @@
+using Aging.Infrastructure.Contracts;
+
+namespace Aging.Infrastructure.Core
+{
+    /// <summary>
+    /// 鎿嶄綔绉熺害瀹炵幇銆�
+    /// 鎻愪緵鐭湡璧勬簮鍗犵敤淇濊瘉锛屾敮鎸佸悓姝ュ拰寮傛閲婃斁銆�
+    /// 閲婃斁鏃堕�氳繃鍥炶皟閫氱煡 ResourceManager銆�
+    /// </summary>
+    public sealed class OperationLease : IOperationLease
+    {
+        private readonly Action? _onRelease;
+        private bool _disposed;
+
+        /// <inheritdoc/>
+        public string LeaseId { get; }
+
+        /// <inheritdoc/>
+        public ResourceKey Resource { get; }
+
+        /// <inheritdoc/>
+        public ResourceOwnerToken Owner { get; }
+
+        /// <inheritdoc/>
+        public DateTime AcquiredAt { get; }
+
+        /// <inheritdoc/>
+        public DateTime? ExpiresAt { get; }
+
+        /// <inheritdoc/>
+        public bool IsValid => !_disposed && !IsExpired();
+
+        /// <summary>
+        /// 鍒濆鍖栨搷浣滅绾﹀疄渚�
+        /// </summary>
+        /// <param name="resource">璧勬簮閿�</param>
+        /// <param name="owner">鎵�鏈夎�呬护鐗�</param>
+        /// <param name="onRelease">閲婃斁鏃剁殑鍥炶皟閫氱煡</param>
+        /// <param name="leaseDurationSeconds">绉熺害鏈夋晥鏈燂紙绉掞級锛岄粯璁�30绉�</param>
+        public OperationLease(
+            ResourceKey resource,
+            ResourceOwnerToken owner,
+            Action? onRelease = null,
+            int leaseDurationSeconds = 30)
+        {
+            LeaseId = Guid.NewGuid().ToString();
+            Resource = resource ?? throw new ArgumentNullException(nameof(resource));
+            Owner = owner ?? throw new ArgumentNullException(nameof(owner));
+            AcquiredAt = DateTime.UtcNow;
+            ExpiresAt = leaseDurationSeconds > 0
+                ? AcquiredAt.AddSeconds(leaseDurationSeconds)
+                : null;
+            _onRelease = onRelease;
+            _disposed = false;
+        }
+
+        /// <summary>
+        /// 妫�鏌ョ绾︽槸鍚﹀凡杩囨湡
+        /// </summary>
+        private bool IsExpired()
+        {
+            if (!ExpiresAt.HasValue)
+                return false;
+            return DateTime.UtcNow > ExpiresAt.Value;
+        }
+
+        /// <inheritdoc/>
+        public void Dispose()
+        {
+            if (_disposed) return;
+            _disposed = true;
+            _onRelease?.Invoke();
+        }
+
+        /// <inheritdoc/>
+        public ValueTask DisposeAsync()
+        {
+            Dispose();
+            return default;
+        }
+    }
+}

--
Gitblit v1.9.1