Imagine you have a Unit of Work / Transaction. Its job is to persist in-memory changes over a REST interface.
You create:
- 10 decks
- Each deck contains 5 cards
You commit the transaction. Because the cards need a deck foreign key, saving to the backend is deferred. The 10 decks are immediately saved.
The server returns:
- Decks 1-9 of the decks are valid
- Deck 10 is invalid because its name isn't unique
Because Decks 1-9 now contain a primary key, the cards belonging to that deck are persisted.
What remains is deck 10 and its associated cards.
You change Deck 10's name, making it potentially valid again. Which of the following options is correct:
- When the deck leave the invalid state, automatically try to persist it again.
- Require the app developer to explicitly try to persist the unit of work again.
If (2), is the user responsible for observing changes to validity and doing the work manually?
Should the choice be an option on the unit of work object?