fix project names
This commit is contained in:
@@ -1,17 +0,0 @@
|
|||||||
using CsharpFp1.Domain;
|
|
||||||
|
|
||||||
namespace CsharpFp1.Application;
|
|
||||||
|
|
||||||
public static class AccountApplicationService
|
|
||||||
{
|
|
||||||
public static void WithdrawMoney(IAccountRepository repository, Guid accountId, decimal amount)
|
|
||||||
{
|
|
||||||
var account =
|
|
||||||
repository.GetById(new AccountId(accountId))
|
|
||||||
?? throw new InvalidOperationException("Account not found.");
|
|
||||||
|
|
||||||
account.Withdraw(new Money(amount));
|
|
||||||
|
|
||||||
repository.Save(account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using CsharpFp1.Application;
|
|
||||||
using CsharpFp1.Domain;
|
|
||||||
using CsharpFp1.Infrastructure;
|
|
||||||
|
|
||||||
namespace CsharpFp1;
|
|
||||||
|
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
public static void Main()
|
|
||||||
{
|
|
||||||
Console.WriteLine("[csharp-fp1] Starting withdraw money demo...");
|
|
||||||
|
|
||||||
var repository = new InMemoryAccountRepository();
|
|
||||||
|
|
||||||
var accountId = Guid.NewGuid();
|
|
||||||
Console.WriteLine($"[csharp-fp1] Seeding account {accountId} with opening balance 200.00");
|
|
||||||
repository.Save(new Account(new AccountId(accountId), new Money(200m)));
|
|
||||||
|
|
||||||
decimal amount = 100m;
|
|
||||||
Console.WriteLine($"[csharp-fp1] Executing withdrawal {amount:0.00} from account {accountId}");
|
|
||||||
AccountApplicationService.WithdrawMoney(repository, accountId, amount);
|
|
||||||
|
|
||||||
Console.WriteLine("[csharp-fp1] Demo completed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using CsharpFp2.Domain;
|
|
||||||
|
|
||||||
namespace CsharpFp2.Application;
|
|
||||||
|
|
||||||
public static class AccountApplicationService
|
|
||||||
{
|
|
||||||
public static void WithdrawMoney(IAccountRepository repository, Guid accountId, decimal amount)
|
|
||||||
{
|
|
||||||
var account =
|
|
||||||
repository.GetById(accountId)
|
|
||||||
?? throw new InvalidOperationException("Account not found.");
|
|
||||||
|
|
||||||
account.Withdraw(new Money(amount));
|
|
||||||
|
|
||||||
repository.Save(account);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using CsharpFp2.Application;
|
|
||||||
using CsharpFp2.Domain;
|
|
||||||
using CsharpFp2.Infrastructure;
|
|
||||||
|
|
||||||
namespace CsharpFp2;
|
|
||||||
|
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
public static void Main()
|
|
||||||
{
|
|
||||||
Console.WriteLine("[csharp-fp2] Starting withdraw money demo...");
|
|
||||||
|
|
||||||
var repository = new InMemoryAccountRepository();
|
|
||||||
|
|
||||||
var accountId = Guid.NewGuid();
|
|
||||||
Console.WriteLine($"[csharp-fp2] Seeding account {accountId} with opening balance 200.00");
|
|
||||||
repository.Save(new Account(accountId, new Money(200m)));
|
|
||||||
|
|
||||||
decimal amount = 100m;
|
|
||||||
Console.WriteLine(
|
|
||||||
$"[csharp-fp2] Executing withdrawal {amount:0.00} from account {accountId}"
|
|
||||||
);
|
|
||||||
AccountApplicationService.WithdrawMoney(repository, accountId, amount);
|
|
||||||
|
|
||||||
Console.WriteLine("[csharp-fp2] Demo completed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using CsharpOopSimplified1.Domain;
|
||||||
|
|
||||||
|
namespace CsharpOopSimplified1.Application;
|
||||||
|
|
||||||
|
public static class AccountApplicationService
|
||||||
|
{
|
||||||
|
public static void WithdrawMoney(IAccountRepository repository, Guid accountId, decimal amount)
|
||||||
|
{
|
||||||
|
var account =
|
||||||
|
repository.GetById(new AccountId(accountId))
|
||||||
|
?? throw new InvalidOperationException("Account not found.");
|
||||||
|
|
||||||
|
Console.WriteLine($"[App] Account loaded. Current balance: {account.Balance.Amount:0.00}");
|
||||||
|
Console.WriteLine($"[App] Executing withdrawal of {amount:0.00}...");
|
||||||
|
|
||||||
|
account.Withdraw(new Money(amount));
|
||||||
|
|
||||||
|
Console.WriteLine($"[App] Withdrawal applied. New balance: {account.Balance.Amount:0.00}");
|
||||||
|
|
||||||
|
repository.Save(account);
|
||||||
|
|
||||||
|
Console.WriteLine("[App] Account persisted.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp1.Domain;
|
namespace CsharpOopSimplified1.Domain;
|
||||||
|
|
||||||
/// Domain entity / aggregate root representing a bank account
|
/// Domain entity / aggregate root representing a bank account
|
||||||
public sealed class Account : AggregateRoot<AccountId>
|
public sealed class Account : AggregateRoot<AccountId>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp1.Domain;
|
namespace CsharpOopSimplified1.Domain;
|
||||||
|
|
||||||
/// Value object used to wrap the aggregate identity
|
/// Value object used to wrap the aggregate identity
|
||||||
public sealed record AccountId(Guid Value);
|
public sealed record AccountId(Guid Value);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp1.Domain;
|
namespace CsharpOopSimplified1.Domain;
|
||||||
|
|
||||||
/// Conventional DDD base type for aggregates
|
/// Conventional DDD base type for aggregates
|
||||||
public abstract class AggregateRoot<TId>
|
public abstract class AggregateRoot<TId>
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp1.Domain;
|
namespace CsharpOopSimplified1.Domain;
|
||||||
|
|
||||||
/// Repository abstraction used to load and save accounts
|
/// Repository abstraction used to load and save accounts
|
||||||
public interface IAccountRepository
|
public interface IAccountRepository
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp1.Domain;
|
namespace CsharpOopSimplified1.Domain;
|
||||||
|
|
||||||
/// Custom domain exception thrown when a withdrawal would cause the balance to go below zero
|
/// Custom domain exception thrown when a withdrawal would cause the balance to go below zero
|
||||||
public sealed class InsufficientBalanceException : InvalidOperationException
|
public sealed class InsufficientBalanceException : InvalidOperationException
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp2.Domain;
|
namespace CsharpOopSimplified1.Domain;
|
||||||
|
|
||||||
/// Value object used to represent money and enforce simple invariants.
|
/// Value object used to represent money and enforce simple invariants.
|
||||||
/// Note that this implementation uses immutable patterns for the data
|
/// Note that this implementation uses immutable patterns for the data
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using CsharpFp1.Domain;
|
using CsharpOopSimplified1.Domain;
|
||||||
|
|
||||||
namespace CsharpFp1.Infrastructure;
|
namespace CsharpOopSimplified1.Infrastructure;
|
||||||
|
|
||||||
/// Simple in-memory repository for demonstration
|
/// Simple in-memory repository for demonstration
|
||||||
public class InMemoryAccountRepository : IAccountRepository
|
public class InMemoryAccountRepository : IAccountRepository
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using CsharpOopSimplified1.Application;
|
||||||
|
using CsharpOopSimplified1.Domain;
|
||||||
|
using CsharpOopSimplified1.Infrastructure;
|
||||||
|
|
||||||
|
namespace CsharpOopSimplified1;
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
Console.WriteLine("[csharp-oop-simplified1] Starting withdraw money demo...");
|
||||||
|
|
||||||
|
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)));
|
||||||
|
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<RootNamespace>csharp_fp1</RootNamespace>
|
<RootNamespace>CsharpOopSimplified1</RootNamespace>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using CsharpOopSimplified2.Domain;
|
||||||
|
|
||||||
|
namespace CsharpOopSimplified2.Application;
|
||||||
|
|
||||||
|
public static class AccountApplicationService
|
||||||
|
{
|
||||||
|
public static void WithdrawMoney(IAccountRepository repository, Guid accountId, decimal amount)
|
||||||
|
{
|
||||||
|
var account =
|
||||||
|
repository.GetById(accountId)
|
||||||
|
?? throw new InvalidOperationException("Account not found.");
|
||||||
|
|
||||||
|
Console.WriteLine($"[App] Account loaded. Current balance: {account.Balance.Amount:0.00}");
|
||||||
|
Console.WriteLine($"[App] Executing withdrawal of {amount:0.00}...");
|
||||||
|
|
||||||
|
account.Withdraw(new Money(amount));
|
||||||
|
|
||||||
|
Console.WriteLine($"[App] Withdrawal applied. New balance: {account.Balance.Amount:0.00}");
|
||||||
|
|
||||||
|
repository.Save(account);
|
||||||
|
|
||||||
|
Console.WriteLine("[App] Account persisted.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp2.Domain;
|
namespace CsharpOopSimplified2.Domain;
|
||||||
|
|
||||||
/// Domain entity / aggregate root representing a bank account
|
/// Domain entity / aggregate root representing a bank account
|
||||||
public sealed class Account
|
public sealed class Account
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp2.Domain;
|
namespace CsharpOopSimplified2.Domain;
|
||||||
|
|
||||||
/// Repository abstraction used to load and save accounts
|
/// Repository abstraction used to load and save accounts
|
||||||
public interface IAccountRepository
|
public interface IAccountRepository
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp2.Domain;
|
namespace CsharpOopSimplified2.Domain;
|
||||||
|
|
||||||
/// Custom domain exception thrown when a withdrawal would cause the balance to go below zero
|
/// Custom domain exception thrown when a withdrawal would cause the balance to go below zero
|
||||||
public sealed class InsufficientBalanceException : InvalidOperationException
|
public sealed class InsufficientBalanceException : InvalidOperationException
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace CsharpFp1.Domain;
|
namespace CsharpOopSimplified2.Domain;
|
||||||
|
|
||||||
/// Value object used to represent money and enforce simple invariants.
|
/// Value object used to represent money and enforce simple invariants.
|
||||||
/// Note that this implementation uses immutable patterns for the data
|
/// Note that this implementation uses immutable patterns for the data
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using CsharpFp2.Domain;
|
using CsharpOopSimplified2.Domain;
|
||||||
|
|
||||||
namespace CsharpFp2.Infrastructure;
|
namespace CsharpOopSimplified2.Infrastructure;
|
||||||
|
|
||||||
/// Simple in-memory repository for demonstration
|
/// Simple in-memory repository for demonstration
|
||||||
public class InMemoryAccountRepository : IAccountRepository
|
public class InMemoryAccountRepository : IAccountRepository
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using CsharpOopSimplified2.Application;
|
||||||
|
using CsharpOopSimplified2.Domain;
|
||||||
|
using CsharpOopSimplified2.Infrastructure;
|
||||||
|
|
||||||
|
namespace CsharpOopSimplified2;
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
Console.WriteLine("[csharp-oop-simplified2] Starting withdraw money demo...");
|
||||||
|
|
||||||
|
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)));
|
||||||
|
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<RootNamespace>csharp_fp2</RootNamespace>
|
<RootNamespace>CsharpOopSimplified2</RootNamespace>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
+4
-4
@@ -11,9 +11,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-oop.Tests", "csharp-
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FP", "FP", "{89C53051-77F9-4C1C-ABE5-6D54AB398471}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FP", "FP", "{89C53051-77F9-4C1C-ABE5-6D54AB398471}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-fp1", "csharp-fp1\csharp-fp1.csproj", "{561BCA96-76DF-4A33-B767-4AD7CD3246B4}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-oop-simplified1", "csharp-oop-simplified1\csharp-oop-simplified1.csproj", "{561BCA96-76DF-4A33-B767-4AD7CD3246B4}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-fp2", "csharp-fp2\csharp-fp2.csproj", "{7237398A-2E8B-4161-BA15-DB090395A1F2}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-oop-simplified2", "csharp-oop-simplified2\csharp-oop-simplified2.csproj", "{7237398A-2E8B-4161-BA15-DB090395A1F2}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -80,7 +80,7 @@ Global
|
|||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{E00F4E4F-8D52-49CE-8754-ED8378A5278F} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA}
|
{E00F4E4F-8D52-49CE-8754-ED8378A5278F} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA}
|
||||||
{9FD0C8F4-A23B-4C68-A365-86E7EF5623D8} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA}
|
{9FD0C8F4-A23B-4C68-A365-86E7EF5623D8} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA}
|
||||||
{561BCA96-76DF-4A33-B767-4AD7CD3246B4} = {89C53051-77F9-4C1C-ABE5-6D54AB398471}
|
{561BCA96-76DF-4A33-B767-4AD7CD3246B4} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA}
|
||||||
{7237398A-2E8B-4161-BA15-DB090395A1F2} = {89C53051-77F9-4C1C-ABE5-6D54AB398471}
|
{7237398A-2E8B-4161-BA15-DB090395A1F2} = {CEC0EC27-0CEC-90C6-CABA-E58AB278E4DA}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Reference in New Issue
Block a user