Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zeromodule/028804d384929ac31136ece954fb8314 to your computer and use it in GitHub Desktop.
Save zeromodule/028804d384929ac31136ece954fb8314 to your computer and use it in GitHub Desktop.
public void WithdrawMoney(decimal amount)
{
Atm atm = _repository.Get();
_atmService.WithdrawMoney(atm, amount);
_repository.Save(_atm);
}
public sealed class AtmService // Domain service
{
public void WithdrawMoney(Atm atm, decimal amount)
{
if (!atm.CanDispenseMoney(amount))
return;
decimal amountWithCommission = atm.CalculateAmountWithCommission(amount);
Result result = _paymentGateway.ChargePayment(amountWithCommission);
if (result.IsFailure)
return;
atm.DispenseMoney(amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment