top-level main programs

This commit is contained in:
Oli Sturm
2026-04-22 13:48:24 +01:00
parent 1b5239566a
commit 1f24bea336
5 changed files with 51 additions and 84 deletions
@@ -8,7 +8,8 @@ public delegate Account? LoadAccount(Guid id);
public delegate void SaveAccount(Account accunt); 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 sealed record AccountPersistence(LoadAccount Load, SaveAccount Save);
public static class InMemoryAccount public static class InMemoryAccount
+10 -20
View File
@@ -2,27 +2,17 @@
using CsharpFp1.Domain; using CsharpFp1.Domain;
using CsharpFp1.Infrastructure; using CsharpFp1.Infrastructure;
namespace CsharpFp1; Console.WriteLine("[csharp-fp1] Starting withdraw money demo...");
public class Program var (loadAccount, saveAccount) = InMemoryAccount.Create();
{ var withdrawMoney = AccountApplication.CreateWithdrawMoney(loadAccount, saveAccount);
public static void Main()
{
Console.WriteLine("[csharp-fp1] Starting withdraw money demo...");
var (loadAccount, saveAccount) = InMemoryAccount.Create(); var accountId = Guid.NewGuid();
var withdrawMoney = AccountApplication.CreateWithdrawMoney(loadAccount, saveAccount); Console.WriteLine($"[csharp-fp1] Seeding account {accountId} with opening balance 200.00");
saveAccount(new Account(accountId, new Money(200m)));
var accountId = Guid.NewGuid(); decimal amount = 100m;
Console.WriteLine($"[csharp-fp1] Seeding account {accountId} with opening balance 200.00"); Console.WriteLine($"[csharp-fp1] Executing withdrawal {amount:0.00} from account {accountId}");
saveAccount(new Account(accountId, new Money(200m))); withdrawMoney(accountId, amount);
decimal amount = 100m; Console.WriteLine("[csharp-fp1] Demo completed.");
Console.WriteLine(
$"[csharp-fp1] Executing withdrawal {amount:0.00} from account {accountId}"
);
withdrawMoney(accountId, amount);
Console.WriteLine("[csharp-fp1] Demo completed.");
}
}
+11 -19
View File
@@ -2,28 +2,20 @@
using CsharpOopSimplified1.Domain; using CsharpOopSimplified1.Domain;
using CsharpOopSimplified1.Infrastructure; using CsharpOopSimplified1.Infrastructure;
namespace CsharpOopSimplified1; Console.WriteLine("[csharp-oop-simplified1] Starting withdraw money demo...");
public class Program var repository = new InMemoryAccountRepository();
{
public static void Main()
{
Console.WriteLine("[csharp-oop-simplified1] Starting withdraw money demo...");
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" $"[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; decimal amount = 100m;
Console.WriteLine( Console.WriteLine(
$"[csharp-oop-simplified1] Executing withdrawal {amount:0.00} from account {accountId}" $"[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.");
}
}
+11 -19
View File
@@ -2,28 +2,20 @@
using CsharpFp1.Domain; using CsharpFp1.Domain;
using CsharpFp1.Infrastructure; using CsharpFp1.Infrastructure;
namespace CsharpFp1; Console.WriteLine("[csharp-oop-simplified2] Starting withdraw money demo...");
public class Program var repository = new InMemoryAccountRepository();
{
public static void Main()
{
Console.WriteLine("[csharp-oop-simplified2] Starting withdraw money demo...");
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" $"[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; decimal amount = 100m;
Console.WriteLine( Console.WriteLine(
$"[csharp-oop-simplified2] Executing withdrawal {amount:0.00} from account {accountId}" $"[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
View File
@@ -3,28 +3,20 @@ using CsharpOop.Contracts;
using CsharpOop.Domain; using CsharpOop.Domain;
using CsharpOop.Infrastructure; using CsharpOop.Infrastructure;
namespace CsharpOop; Console.WriteLine("[csharp-oop] Starting withdraw money demo...");
public class Program var repository = new InMemoryAccountRepository();
{ var handler = new WithdrawMoneyHandler(repository);
public static void Main()
{
Console.WriteLine("[csharp-oop] Starting withdraw money demo...");
var repository = new InMemoryAccountRepository(); var accountId = Guid.NewGuid();
var handler = new WithdrawMoneyHandler(repository); 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(); var command = new WithdrawMoneyCommand { AccountId = accountId, Amount = 100m };
Console.WriteLine($"[csharp-oop] Seeding account {accountId} with opening balance 200.00"); Console.WriteLine(
repository.Save(new Account(new AccountId(accountId), new Money(200m)));
var command = new WithdrawMoneyCommand { AccountId = accountId, Amount = 100m };
Console.WriteLine(
$"[csharp-oop] Dispatching command: withdraw {command.Amount:0.00} from account {command.AccountId}" $"[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.");
}
}