diff --git a/csharp-fp1/Infrastructure/InMemoryAccountRepository.cs b/csharp-fp1/Infrastructure/InMemoryAccount.cs similarity index 82% rename from csharp-fp1/Infrastructure/InMemoryAccountRepository.cs rename to csharp-fp1/Infrastructure/InMemoryAccount.cs index 7d371a7..d5e56ef 100644 --- a/csharp-fp1/Infrastructure/InMemoryAccountRepository.cs +++ b/csharp-fp1/Infrastructure/InMemoryAccount.cs @@ -8,8 +8,9 @@ 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 -// public sealed record AccountPersistence(LoadAccount Load, SaveAccount Save); +// 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 { diff --git a/csharp-fp1/Program.cs b/csharp-fp1/Program.cs index 51949d5..33f9227 100644 --- a/csharp-fp1/Program.cs +++ b/csharp-fp1/Program.cs @@ -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."); diff --git a/csharp-oop-simplified1/Program.cs b/csharp-oop-simplified1/Program.cs index 1f40001..33eecb8 100644 --- a/csharp-oop-simplified1/Program.cs +++ b/csharp-oop-simplified1/Program.cs @@ -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( + $"[csharp-oop-simplified1] 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-simplified1] Seeding account {accountId} with opening balance 200.00" - ); - repository.Save(new Account(new AccountId(accountId), new Money(200m))); +decimal amount = 100m; +Console.WriteLine( + $"[csharp-oop-simplified1] Executing withdrawal {amount:0.00} from account {accountId}" +); +AccountApplicationService.WithdrawMoney(repository, accountId, amount); - decimal amount = 100m; - Console.WriteLine( - $"[csharp-oop-simplified1] Executing withdrawal {amount:0.00} from account {accountId}" - ); - AccountApplicationService.WithdrawMoney(repository, accountId, amount); - - Console.WriteLine("[csharp-oop-simplified1] Demo completed."); - } -} +Console.WriteLine("[csharp-oop-simplified1] Demo completed."); diff --git a/csharp-oop-simplified2/Program.cs b/csharp-oop-simplified2/Program.cs index e5102be..b3362d9 100644 --- a/csharp-oop-simplified2/Program.cs +++ b/csharp-oop-simplified2/Program.cs @@ -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( + $"[csharp-oop-simplified2] Seeding account {accountId} with opening balance 200.00" +); +repository.Save(new Account(accountId, new Money(200m))); - 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))); +decimal amount = 100m; +Console.WriteLine( + $"[csharp-oop-simplified2] Executing withdrawal {amount:0.00} from account {accountId}" +); +AccountApplicationService.WithdrawMoney(repository, accountId, amount); - decimal amount = 100m; - Console.WriteLine( - $"[csharp-oop-simplified2] Executing withdrawal {amount:0.00} from account {accountId}" - ); - AccountApplicationService.WithdrawMoney(repository, accountId, amount); - - Console.WriteLine("[csharp-oop-simplified2] Demo completed."); - } -} +Console.WriteLine("[csharp-oop-simplified2] Demo completed."); diff --git a/csharp-oop/Program.cs b/csharp-oop/Program.cs index f282ef9..bd9add3 100644 --- a/csharp-oop/Program.cs +++ b/csharp-oop/Program.cs @@ -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( + $"[csharp-oop] Dispatching command: withdraw {command.Amount:0.00} from account {command.AccountId}" +); - 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.");