diff --git a/orleans/BankAccount/AccountTransfer.Grains/AccountGrain.cs b/orleans/BankAccount/AccountTransfer.Grains/AccountGrain.cs index 93ba3c663c8..97b71f422d6 100644 --- a/orleans/BankAccount/AccountTransfer.Grains/AccountGrain.cs +++ b/orleans/BankAccount/AccountTransfer.Grains/AccountGrain.cs @@ -1,14 +1,13 @@ -using AccountTransfer.Interfaces; +using AccountTransfer.Interfaces; using Orleans.Concurrency; using Orleans.Transactions.Abstractions; namespace AccountTransfer.Grains; -[GenerateSerializer] +[GenerateSerializer, Immutable] public record class Balance { - [Id(0)] - public int Value { get; set; } = 1_000; + public int Value { get; init; } = 1_000; } [Reentrant] @@ -22,7 +21,7 @@ public AccountGrain( public Task Deposit(int amount) => _balance.PerformUpdate( - balance => balance.Value += amount); + balance => balance with { Value = balance.Value + amount }); public Task Withdraw(int amount) => _balance.PerformUpdate(balance => @@ -35,7 +34,7 @@ public Task Withdraw(int amount) => $" This account has {balance.Value} credits."); } - balance.Value -= amount; + return balance with { Value = balance.Value + amount }; }); public Task GetBalance() =>