forked from bmaluijb/CloudDesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
34 lines (28 loc) · 1.19 KB
/
Program.cs
File metadata and controls
34 lines (28 loc) · 1.19 KB
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
using System;
namespace EventSourcingPattern
{
class Program
{
static void Main(string[] args)
{
using (EventStore store = new EventStore())
{
//create a new streamID. This wil be used for partitioning
Guid streamId = Guid.NewGuid();
//create things that happened
var depositevent1 = new CashDepositCommand { Amount = 100, EventId = Guid.NewGuid() };
var depositevent2 = new CashDepositCommand { Amount = 20, EventId = Guid.NewGuid() };
var withdrawalevent1 = new CashWithdrawalCommand { Amount = -75, EventId = Guid.NewGuid() };
//100 + 20 - 75 = 45
//commit those things
store.AppendToStream(streamId, depositevent1);
store.AppendToStream(streamId, depositevent2);
store.AppendToStream(streamId, withdrawalevent1);
//replay the events and get the current state of the data
double stateOfData = store.GetAmount(streamId);
Console.WriteLine("Balance: " + stateOfData);
Console.ReadLine();
}
}
}
}