-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathAggregateDemo.cs
49 lines (42 loc) · 1.74 KB
/
AggregateDemo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Linq;
using System.Threading.Tasks;
using Demo.SmartCache.GrainInterfaces;
using Orleans;
using Patterns.DevBreadboard;
namespace Patterns.SmartCache.Host
{
internal class AggregateDemo
{
public static async Task Run()
{
var accountAggregateGrain =
GrainClient.GrainFactory.GetGrain<IBankAccountAggregateGrain>(Constants.BankAccountAggregateGrainId);
var accountGrains =
Constants.BankAccountGrainIds.Select(id => GrainClient.GrainFactory.GetGrain<IBankAccountGrain>(id))
.ToList();
// register the account grains with the aggregate
foreach (var accountGrain in accountGrains)
{
await accountAggregateGrain.RegisterGrain(accountGrain);
}
// run a set of operations...
foreach (var accountGrain in accountGrains.Take(10))
{
await accountGrain.CreditAmount(100.0M);
}
//...and see the aggregate value updated consequently
var totalBalance = await accountAggregateGrain.GetAggregateValue();
Console.WriteLine($"Total Balance (should be 10 * 100) {totalBalance.Value.Balance}");
// run another set of operations...
foreach (var accountGrain in accountGrains.Take(10))
{
await accountGrain.CreditAmount(100.0M);
}
// ...and see the aggregate value accumulate
totalBalance = await accountAggregateGrain.GetAggregateValue();
Console.WriteLine($"Total Balance (should be 10 * 100 * 2) {totalBalance.Value.Balance}");
DevelopmentSiloHost.WaitForInteraction();
}
}
}