-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Pointers #45
Merged
Merged
Feat: Pointers #45
Conversation
This file contains 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
to start.. it is going to be beneficial to make projections have a GetId and GetVersionNumber method added because projections can be snapshots, and the aim of this PR is to use the new "pointer" concept to address snapshots.. now, in the common library, both an entity and a projection are intended to be used with snapshots - there's quite a bit of code for snapshots that works with both! to that end, let's just formalize the relationship and move the common methods (Construct, GetId, GetVersionNumber) to the ISnapshot interface and refactor all of the resulting redundancies
always uses minimum version number, useful for getting most recent snapshot with little code
move the corresponding logic into the IProjection interface
when in non-test mode, register the subscriber as a hosted background service and use a buffer block instead of calling Task.Run(...) and not waiting.
the-avid-engineer
added
diff:remove
Pull Request removes an existing feature
diff:deprecate
Code has been marked as obsolete, but still works
diff:refactor:internal
Code has been refactored in a way that will not cause compiler errors
labels
Jun 27, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
diff:deprecate
Code has been marked as obsolete, but still works
diff:refactor:internal
Code has been refactored in a way that will not cause compiler errors
diff:remove
Pull Request removes an existing feature
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.
It would be useful for the
ISnapshotRepository
,IEntityRepository
, andIProjectionRepository
instances to be able to get entities at any version instead of always pulling the latest version.To that end, introduce a new value object, the pointer:
For
ISnapshotRepository
, mark the existingGetSnapshot
method as obsolete and forward the call to the newGetSnapshotOrDefault
method, which accepts aPointer
instead of anId
For
IEntityRepository
andIProjectionRepository
, mark the existingGetCurrent
andGetAtVersion
methods as obsolete and forward the call to the newGetSnapshot
method, which accepts aPointer
instead of anId
Affected Snapshot Repository Implementations
Redis
The Redis snapshot key will be changed from
{keyNamespace}#{snapshotId}
to{keyNamespace}#{snapshotPointer.Id}@{snapshotPointer.VersionNumber}
In Memory
The in-memory snapshot repository will simply use
Pointer
as the dictionary key instead ofId
Additional Changes
Transaction Subscribers
The
TransactionSubscriber
has been buffed in non-test mode. Instead of callingTask.Run
and ignoring the result, it will now add the result to a BufferBlock. (Note: Test mode still usesTask.Run(...).Wait()
so that transactions are processed synchronously.) In addition, the transaction subscriber will be registered as a BackgroundService and will process the BufferBlock asynchronously. This processor is also try-catched, so any failed processes will not cause the background service to stop.Entity & Projection Snapshot Transaction Subscribers
The entity snapshot subscriber and projection snapshot subscriber have been refactored to implement
ITransactionProcessor
and are registered usingTransactionProcessorSubscriber
. The two processors have a common base class which abstracts some redundant work and also provides a caching mechanism to avoid hitting the database multiple times.You also must provide a transaction session options name now, as it is possible to hit the database if snapshots don't have all of the information needed.
Entity & Projection Repositories
These repositories will no longer return the default snapshot state - if the expected pointer cannot be loaded, they will always throw
SnapshotPointerDoesNotExistException
(which replaces theEntityNotCreatedException
that was originally thrown on the now-obsoleteGetCurrent
method)Entity, Projection and Snapshot - Common Library Interfaces
Some common functionality between
IEntity<>
andIProjection<>
(e.g.,GetId
,GetVersionNumber
,Construct
) have been moved to theISnapshot<>
interface, and these common library interfaces now extendISnapshot<>
ISnapshot<>
has two new method,ShouldRecord
andShouldRecordAsLatest
, the latter of which replaces the now-obsoleteShouldReplace
Projections
The
IProjectionStrategy
interface has been removed - the functionality has been moved to theIProjection<>
interface, more or less. To accomplish this, there are two methods:GetProjectionIdOrDefault
- this will statically map anobject
to anId?
GetCommandQuery
- this will dynamically map the projection and projection pointer to any query you want - it should load all of the commands which are needed to reach the projection pointer.Because you now control the query, the
GetEntityVersionNumber
method has been removed.