Skip to content

Commit 15d783a

Browse files
committed
- Checkpoint: Simplified Saga and Events
1 parent 85252c3 commit 15d783a

23 files changed

Lines changed: 187 additions & 265 deletions

src/SourceFlow.ConsoleApp/Aggregates/AccountAggregate.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using Microsoft.Extensions.Logging;
21
using SourceFlow.ConsoleApp.Commands;
3-
using SourceFlow.Events;
2+
using SourceFlow.ConsoleApp.Events;
43

54
namespace SourceFlow.ConsoleApp.Aggregates
65
{
76
public class AccountAggregate : BaseAggregate<BankAccount>,
8-
IEventHandler<EntityCreated<BankAccount>>
7+
IEventHandler<AccountCreated>
98

109
{
1110
public void CreateAccount(int accountId, string holder, decimal amount)
@@ -47,16 +46,13 @@ public void Close(int accountId, string reason)
4746
}));
4847
}
4948

50-
public Task Handle(EntityCreated<BankAccount> @event)
49+
public Task Handle(AccountCreated @event)
5150
{
52-
if (@event.Name != "BankAccountCreated")
53-
return Task.CompletedTask;
54-
5551
return PublishAsync(Command.For<BankAccount>(@event.Payload.Id)
56-
.Create<ActivateAccount, ActivationPayload>(new ActivationPayload
57-
{
58-
ActiveOn = DateTime.UtcNow,
59-
}));
52+
.Create<ActivateAccount, ActivationPayload>(new ActivationPayload
53+
{
54+
ActiveOn = DateTime.UtcNow,
55+
}));
6056
}
6157
}
6258
}

src/SourceFlow.ConsoleApp/Commands/AccountCommand.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace SourceFlow.ConsoleApp.Commands
22
{
3-
public class ActivateAccount : AccountCommand<ActivationPayload>
3+
public class ActivateAccount : BaseCommand<ActivationPayload>
44
{
55
}
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace SourceFlow.ConsoleApp.Commands
22
{
3-
public class CloseAccount : AccountCommand<ClosurePayload>
3+
public class CloseAccount : BaseCommand<ClosurePayload>
44
{
55
}
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace SourceFlow.ConsoleApp.Commands
22
{
3-
public class CreateAccount : AccountCommand<AccountPayload>
3+
public class CreateAccount : BaseCommand<AccountPayload>
44
{
55
}
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace SourceFlow.ConsoleApp.Commands
22
{
3-
public class DepositMoney : AccountCommand<TransactPayload>
3+
public class DepositMoney : BaseCommand<TransactPayload>
44
{
55
}
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace SourceFlow.ConsoleApp.Commands
22
{
3-
public class WithdrawMoney : AccountCommand<TransactPayload>
3+
public class WithdrawMoney : BaseCommand<TransactPayload>
44
{
55
}
66
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using SourceFlow.ConsoleApp.Aggregates;
2+
3+
namespace SourceFlow.ConsoleApp.Events
4+
{
5+
public class AccountCreated : BaseEvent<BankAccount>
6+
{
7+
public AccountCreated(BankAccount payload) : base(payload)
8+
{
9+
}
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using SourceFlow.ConsoleApp.Aggregates;
2+
3+
namespace SourceFlow.ConsoleApp.Events
4+
{
5+
public class AccountUpdated : BaseEvent<BankAccount>
6+
{
7+
public AccountUpdated(BankAccount payload) : base(payload)
8+
{
9+
}
10+
}
11+
}

src/SourceFlow.ConsoleApp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Microsoft.Extensions.Logging;
33
using SourceFlow;
44
using SourceFlow.ConsoleApp.Services;
5-
using SourceFlow.ConsoleApp.ViewModels; // Ensure this using is present
5+
using SourceFlow.ConsoleApp.Views; // Ensure this using is present
66

77
var services = new ServiceCollection();
88

0 commit comments

Comments
 (0)