Skip to content

Commit d07f86a

Browse files
committed
- Checkpoint: Split Events vs Commands
1 parent 970c453 commit d07f86a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+760
-562
lines changed

src/SourceFlow.ConsoleApp/Aggregates/AccountAggregate.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using SourceFlow.ConsoleApp.Events;
1+
using SourceFlow.ConsoleApp.Commands;
22

33
namespace SourceFlow.ConsoleApp.Aggregates
44
{
55
public class AccountAggregate : BaseAggregate<BankAccount>
66
{
77
public void CreateAccount(int accountId, string holder, decimal amount)
88
{
9-
PublishAsync(Event.For<BankAccount>(accountId)
10-
.Create<AccountCreated, AccountPayload>(new AccountPayload
9+
PublishAsync(Command.For<BankAccount>(accountId)
10+
.Create<CreateAccount, AccountPayload>(new AccountPayload
1111
{
1212
AccountName = holder,
1313
InitialAmount = amount
@@ -16,8 +16,8 @@ public void CreateAccount(int accountId, string holder, decimal amount)
1616

1717
public void Deposit(int accountId, decimal amount)
1818
{
19-
PublishAsync(Event.For<BankAccount>(accountId)
20-
.Create<MoneyDeposited, TransactPayload>(new TransactPayload
19+
PublishAsync(Command.For<BankAccount>(accountId)
20+
.Create<DepositMoney, TransactPayload>(new TransactPayload
2121
{
2222
Amount = amount,
2323
Type = TransactionType.Deposit
@@ -26,8 +26,8 @@ public void Deposit(int accountId, decimal amount)
2626

2727
public void Withdraw(int accountId, decimal amount)
2828
{
29-
PublishAsync(Event.For<BankAccount>(accountId)
30-
.Create<MoneyWithdrawn, TransactPayload>(new TransactPayload
29+
PublishAsync(Command.For<BankAccount>(accountId)
30+
.Create<WithdrawMoney, TransactPayload>(new TransactPayload
3131
{
3232
Amount = amount,
3333
Type = TransactionType.Withdrawal
@@ -36,8 +36,8 @@ public void Withdraw(int accountId, decimal amount)
3636

3737
public void Close(int accountId, string reason)
3838
{
39-
PublishAsync(Event.For<BankAccount>(accountId)
40-
.Create<AccountClosed, ClosurePayload>(new ClosurePayload
39+
PublishAsync(Command.For<BankAccount>(accountId)
40+
.Create<CloseAccount, ClosurePayload>(new ClosurePayload
4141
{
4242
ClosureReason = reason
4343
}));

src/SourceFlow.ConsoleApp/Aggregates/BankAccount.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace SourceFlow.ConsoleApp.Aggregates
33
public class BankAccount : IEntity
44
{
55
public int Id { get; set; }
6+
public DateTime CreatedOn { get; set; } = DateTime.UtcNow;
67
public string AccountName { get; set; } = string.Empty;
78
public decimal Balance { get; set; }
89
public bool IsClosed { get; set; }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceFlow.ConsoleApp.Commands
2+
{
3+
public abstract class AccountCommand<TPayload> : BaseCommand<TPayload> where TPayload : class, IPayload, new()
4+
{
5+
}
6+
}

src/SourceFlow.ConsoleApp/Events/AccountPayload.cs renamed to src/SourceFlow.ConsoleApp/Commands/AccountPayload.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
using SourceFlow.ConsoleApp.Aggregates;
22

3-
namespace SourceFlow.ConsoleApp.Events
3+
namespace SourceFlow.ConsoleApp.Commands
44
{
5-
public class AccountPayload : IEventPayload
5+
public class AccountPayload : IPayload
66
{
77
public decimal InitialAmount { get; set; }
88
public string AccountName { get; set; }
99
}
1010

11-
public class TransactPayload : IEventPayload
11+
public class TransactPayload : IPayload
1212
{
1313
public TransactionType Type { get; set; }
1414
public decimal Amount { get; set; }
1515
public decimal CurrentBalance { get; set; }
1616
}
1717

18-
public class ClosurePayload : IEventPayload
18+
public class ClosurePayload : IPayload
1919
{
2020
public bool IsClosed { get; set; }
2121
public string ClosureReason { get; set; } = string.Empty;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceFlow.ConsoleApp.Commands
2+
{
3+
public class CloseAccount : AccountCommand<ClosurePayload>
4+
{
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceFlow.ConsoleApp.Commands
2+
{
3+
public class CreateAccount : AccountCommand<AccountPayload>
4+
{
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceFlow.ConsoleApp.Commands
2+
{
3+
public class DepositMoney : AccountCommand<TransactPayload>
4+
{
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace SourceFlow.ConsoleApp.Commands
2+
{
3+
public class WithdrawMoney : AccountCommand<TransactPayload>
4+
{
5+
}
6+
}

src/SourceFlow.ConsoleApp/Events/AccountClosed.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using SourceFlow.ConsoleApp.Aggregates;
7+
18
namespace SourceFlow.ConsoleApp.Events
29
{
3-
public class AccountCreated : AccountEvent<AccountPayload>
4-
{
5-
}
610
}

0 commit comments

Comments
 (0)