Skip to content

Conversation

the-avid-engineer
Copy link
Member

@the-avid-engineer the-avid-engineer commented Feb 23, 2022

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 be 0.

The motivation is that EntityDb is serving four main purposes, but does not allow you to use them independently:

  1. Tracing - The AgentSignatures database, tells you where a Transaction came from
  2. Event Sourcing - The Commands database, tells you how the State has been modified
  3. Resource Tagging - The Tags database, provides immediately consistent querying
  4. Uniqueness Constraints - The Leases database, provides guarantees of unique data

To 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() and GetTags() methods have been removed from the common IEntity<TEntity> interface; the common implementation of TransactionStep<TEntity> is renamed CommandTransactionStep<TEntity> and implements only the ICommandTransactionStep<TEntity> interface.

In addition, there are new common implementations of LeaseTransactionStep<TEntity> and TagTransactionStep<TEntity> objects, which are used by the TransactionBuilder<TEntity>

The TransactionBuilder<TEntity> drops the Create method in favor of always calling Append for commands, and creating an initial state of the TEntity if none is already loaded into memory. It additionally has Add and Delete methods for arrays of ILease or ITag, 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.

@the-avid-engineer the-avid-engineer merged commit ddf6778 into main Feb 24, 2022
@the-avid-engineer the-avid-engineer deleted the feat/transaction-step-types branch February 24, 2022 17:35
@the-avid-engineer the-avid-engineer added diff:add Code has been added diff:refactor:break Code has been refactored in a way that will cause compiler errors and does not fix a bug diff:remove Pull Request removes an existing feature labels Jun 25, 2022
@the-avid-engineer the-avid-engineer self-assigned this Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diff:add Code has been added diff:refactor:break Code has been refactored in a way that will cause compiler errors and does not fix a bug diff:remove Pull Request removes an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant