Browse Source

Fix a state bug in `InventoryActor`

pull/208/head
gdlcf88 4 years ago
parent
commit
703acd1952
  1. 8
      plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs

8
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<InventoryStateModel> GetInventoryStateAsync() =>
StateManager.GetStateAsync<InventoryStateModel>(InventoryStateName);
public virtual async Task<InventoryStateModel> GetInventoryStateAsync() =>
State ??= await StateManager.GetStateAsync<InventoryStateModel>(InventoryStateName);
public virtual async Task IncreaseInventoryAsync(int quantity, bool decreaseSold, bool isFlashSale)
{

Loading…
Cancel
Save