Skip to content

Instantly share code, notes, and snippets.

@wycats
Created February 11, 2012 03:07
Show Gist options
  • Save wycats/1795649 to your computer and use it in GitHub Desktop.
Save wycats/1795649 to your computer and use it in GitHub Desktop.

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:

  1. When the deck leave the invalid state, automatically try to persist it again.
  2. 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment