-
-
Save dcomartin/51c7d6a7f0467bb0e42a2226a14fb24f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task Handle(PayOrder cmd) | |
| { | |
| // ❌ External side effect BEFORE we know our transaction will commit | |
| var receipt = await _paymentGateway.Charge(cmd.OrderId, cmd.Amount); | |
| using var tx = _db.BeginTransaction(); | |
| _db.Inbox.Add(new InboxMessage(cmd.MessageId)); // UNIQUE(MessageId) | |
| var order = _db.Orders.Find(cmd.OrderId); | |
| order.MarkPaid(receipt.Id); | |
| await _db.SaveChangesAsync(); | |
| await tx.CommitAsync(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment