Feat: Transaction Step Types #26
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The purpose of this PR is to provide a way to commit leases (and tags) without having to commit commands. In fact, this is now the only way to do so. If you commit a lease before you commit a command, it is effectively "preleasing" the entity, as the recorded
EntityVersionNumber
will be0
.The motivation is that EntityDb is serving four main purposes, but does not allow you to use them independently:
AgentSignatures
database, tells you where a Transaction came fromCommands
database, tells you how the State has been modifiedTags
database, provides immediately consistent queryingLeases
database, provides guarantees of unique dataTo accomplish such a feature, this PR introduces subclasses of transaction steps. To that end, the
ITransactionStep<TEntity>
interface is broken into pieces:ICommandTransactionStep<TEntity>
ILeaseTransactionStep<TEntity>
ITagTransactionStep<TEntity>
Note: There is no transaction step for agent signatures because only one agent signature is recorded per transaction, no matter how many steps it has. If you wanted, for whatever reason, to commit a transaction with no steps in it just for the sake of adding an agent signature record, you already have that ability.
Further..
The
GetLeases()
andGetTags()
methods have been removed from the commonIEntity<TEntity>
interface; the common implementation ofTransactionStep<TEntity>
is renamedCommandTransactionStep<TEntity>
and implements only theICommandTransactionStep<TEntity>
interface.In addition, there are new common implementations of
LeaseTransactionStep<TEntity>
andTagTransactionStep<TEntity>
objects, which are used by theTransactionBuilder<TEntity>
The
TransactionBuilder<TEntity>
drops theCreate
method in favor of always callingAppend
for commands, and creating an initial state of theTEntity
if none is already loaded into memory. It additionally hasAdd
andDelete
methods for arrays ofILease
orITag
, and calling these methods will add transaction steps which only add or delete tags or leases.Finally,
Transaction subscribers can decide what to do by checking which interfaces are implemented on a step, such as sending or not sending a message to notify the world about the change.