Skip to content

Commit 7a91f98

Browse files
committed
Code Review suggestions and bug fixes.
Made Balance a class instead of a record as no benefit in using record here. Added Id attribute to Balance.Value so that it is serialized and to allow state to be persisted after a Withdrawal. Removed Reentrant attribute from AccountGrain as this could introduce race conditions when using Transactions.
1 parent aa19cbe commit 7a91f98

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

orleans/BankAccount/AccountTransfer.Grains/AccountGrain.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using AccountTransfer.Interfaces;
2-
using Orleans.Concurrency;
32
using Orleans.Transactions.Abstractions;
43

54
namespace AccountTransfer.Grains;
65

76
[GenerateSerializer]
8-
public class class Balance
7+
public class Balance
98
{
9+
[Id(0)]
1010
public int Value { get; set; } = 1_000;
1111
}
1212

13-
[Reentrant]
1413
public sealed class AccountGrain : Grain, IAccountGrain
1514
{
1615
private readonly ITransactionalState<Balance> _balance;
@@ -34,7 +33,7 @@ public Task Withdraw(int amount) =>
3433
$" This account has {balance.Value} credits.");
3534
}
3635

37-
balance = balance.Value -= amount;
36+
balance.Value -= amount;
3837
});
3938

4039
public Task<int> GetBalance() =>

0 commit comments

Comments
 (0)