diff --git a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs b/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs index ce3ca9b0..73f8963c 100644 --- a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs +++ b/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs @@ -2,6 +2,7 @@ using System; using System.Threading.Tasks; using Dapr; using Dapr.Actors.Runtime; +using JetBrains.Annotations; namespace EasyAbp.EShop.Plugins.Inventories.DaprActors; @@ -11,6 +12,9 @@ public class InventoryActor : Actor, IInventoryActor protected bool FlashSalesInventoryUpdated { get; set; } + [CanBeNull] + protected InventoryStateModel State { get; set; } + public InventoryActor(ActorHost host) : base(host) { } @@ -20,8 +24,8 @@ public class InventoryActor : Actor, IInventoryActor await StateManager.TryAddStateAsync(InventoryStateName, new InventoryStateModel()); } - public virtual Task GetInventoryStateAsync() => - StateManager.GetStateAsync(InventoryStateName); + public virtual async Task GetInventoryStateAsync() => + State ??= await StateManager.GetStateAsync(InventoryStateName); public virtual async Task IncreaseInventoryAsync(int quantity, bool decreaseSold, bool isFlashSale) {