top-level main programs
This commit is contained in:
+2
-1
@@ -8,7 +8,8 @@ public delegate Account? LoadAccount(Guid id);
|
||||
|
||||
public delegate void SaveAccount(Account accunt);
|
||||
|
||||
// If we don't want to use tuples or really miss the interface idea, we can create a named container
|
||||
// If we don't want to use tuples, or you really miss the idea of a combined "interface",
|
||||
// we can create a named container
|
||||
// public sealed record AccountPersistence(LoadAccount Load, SaveAccount Save);
|
||||
|
||||
public static class InMemoryAccount
|
||||
+10
-20
@@ -2,27 +2,17 @@
|
||||
using CsharpFp1.Domain;
|
||||
using CsharpFp1.Infrastructure;
|
||||
|
||||
namespace CsharpFp1;
|
||||
Console.WriteLine("[csharp-fp1] Starting withdraw money demo...");
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("[csharp-fp1] Starting withdraw money demo...");
|
||||
var (loadAccount, saveAccount) = InMemoryAccount.Create();
|
||||
var withdrawMoney = AccountApplication.CreateWithdrawMoney(loadAccount, saveAccount);
|
||||
|
||||
var (loadAccount, saveAccount) = InMemoryAccount.Create();
|
||||
var withdrawMoney = AccountApplication.CreateWithdrawMoney(loadAccount, saveAccount);
|
||||
var accountId = Guid.NewGuid();
|
||||
Console.WriteLine($"[csharp-fp1] Seeding account {accountId} with opening balance 200.00");
|
||||
saveAccount(new Account(accountId, new Money(200m)));
|
||||
|
||||
var accountId = Guid.NewGuid();
|
||||
Console.WriteLine($"[csharp-fp1] Seeding account {accountId} with opening balance 200.00");
|
||||
saveAccount(new Account(accountId, new Money(200m)));
|
||||
decimal amount = 100m;
|
||||
Console.WriteLine($"[csharp-fp1] Executing withdrawal {amount:0.00} from account {accountId}");
|
||||
withdrawMoney(accountId, amount);
|
||||
|
||||
decimal amount = 100m;
|
||||
Console.WriteLine(
|
||||
$"[csharp-fp1] Executing withdrawal {amount:0.00} from account {accountId}"
|
||||
);
|
||||
withdrawMoney(accountId, amount);
|
||||
|
||||
Console.WriteLine("[csharp-fp1] Demo completed.");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("[csharp-fp1] Demo completed.");
|
||||
|
||||
@@ -2,28 +2,20 @@
|
||||
using CsharpOopSimplified1.Domain;
|
||||
using CsharpOopSimplified1.Infrastructure;
|
||||
|
||||
namespace CsharpOopSimplified1;
|
||||
Console.WriteLine("[csharp-oop-simplified1] Starting withdraw money demo...");
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("[csharp-oop-simplified1] Starting withdraw money demo...");
|
||||
var repository = new InMemoryAccountRepository();
|
||||
|
||||
var repository = new InMemoryAccountRepository();
|
||||
|
||||
var accountId = Guid.NewGuid();
|
||||
Console.WriteLine(
|
||||
var accountId = Guid.NewGuid();
|
||||
Console.WriteLine(
|
||||
$"[csharp-oop-simplified1] Seeding account {accountId} with opening balance 200.00"
|
||||
);
|
||||
repository.Save(new Account(new AccountId(accountId), new Money(200m)));
|
||||
);
|
||||
repository.Save(new Account(new AccountId(accountId), new Money(200m)));
|
||||
|
||||
decimal amount = 100m;
|
||||
Console.WriteLine(
|
||||
decimal amount = 100m;
|
||||
Console.WriteLine(
|
||||
$"[csharp-oop-simplified1] Executing withdrawal {amount:0.00} from account {accountId}"
|
||||
);
|
||||
AccountApplicationService.WithdrawMoney(repository, accountId, amount);
|
||||
);
|
||||
AccountApplicationService.WithdrawMoney(repository, accountId, amount);
|
||||
|
||||
Console.WriteLine("[csharp-oop-simplified1] Demo completed.");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("[csharp-oop-simplified1] Demo completed.");
|
||||
|
||||
@@ -2,28 +2,20 @@
|
||||
using CsharpFp1.Domain;
|
||||
using CsharpFp1.Infrastructure;
|
||||
|
||||
namespace CsharpFp1;
|
||||
Console.WriteLine("[csharp-oop-simplified2] Starting withdraw money demo...");
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("[csharp-oop-simplified2] Starting withdraw money demo...");
|
||||
var repository = new InMemoryAccountRepository();
|
||||
|
||||
var repository = new InMemoryAccountRepository();
|
||||
|
||||
var accountId = Guid.NewGuid();
|
||||
Console.WriteLine(
|
||||
var accountId = Guid.NewGuid();
|
||||
Console.WriteLine(
|
||||
$"[csharp-oop-simplified2] Seeding account {accountId} with opening balance 200.00"
|
||||
);
|
||||
repository.Save(new Account(accountId, new Money(200m)));
|
||||
);
|
||||
repository.Save(new Account(accountId, new Money(200m)));
|
||||
|
||||
decimal amount = 100m;
|
||||
Console.WriteLine(
|
||||
decimal amount = 100m;
|
||||
Console.WriteLine(
|
||||
$"[csharp-oop-simplified2] Executing withdrawal {amount:0.00} from account {accountId}"
|
||||
);
|
||||
AccountApplicationService.WithdrawMoney(repository, accountId, amount);
|
||||
);
|
||||
AccountApplicationService.WithdrawMoney(repository, accountId, amount);
|
||||
|
||||
Console.WriteLine("[csharp-oop-simplified2] Demo completed.");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("[csharp-oop-simplified2] Demo completed.");
|
||||
|
||||
+11
-19
@@ -3,28 +3,20 @@ using CsharpOop.Contracts;
|
||||
using CsharpOop.Domain;
|
||||
using CsharpOop.Infrastructure;
|
||||
|
||||
namespace CsharpOop;
|
||||
Console.WriteLine("[csharp-oop] Starting withdraw money demo...");
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("[csharp-oop] Starting withdraw money demo...");
|
||||
var repository = new InMemoryAccountRepository();
|
||||
var handler = new WithdrawMoneyHandler(repository);
|
||||
|
||||
var repository = new InMemoryAccountRepository();
|
||||
var handler = new WithdrawMoneyHandler(repository);
|
||||
var accountId = Guid.NewGuid();
|
||||
Console.WriteLine($"[csharp-oop] Seeding account {accountId} with opening balance 200.00");
|
||||
repository.Save(new Account(new AccountId(accountId), new Money(200m)));
|
||||
|
||||
var accountId = Guid.NewGuid();
|
||||
Console.WriteLine($"[csharp-oop] Seeding account {accountId} with opening balance 200.00");
|
||||
repository.Save(new Account(new AccountId(accountId), new Money(200m)));
|
||||
|
||||
var command = new WithdrawMoneyCommand { AccountId = accountId, Amount = 100m };
|
||||
Console.WriteLine(
|
||||
var command = new WithdrawMoneyCommand { AccountId = accountId, Amount = 100m };
|
||||
Console.WriteLine(
|
||||
$"[csharp-oop] Dispatching command: withdraw {command.Amount:0.00} from account {command.AccountId}"
|
||||
);
|
||||
);
|
||||
|
||||
handler.Handle(command);
|
||||
handler.Handle(command);
|
||||
|
||||
Console.WriteLine("[csharp-oop] Demo completed.");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("[csharp-oop] Demo completed.");
|
||||
|
||||
Reference in New Issue
Block a user