示例#1
0
        public void SetFromLoad(TAggregate aggregate)
        {
            _entries.Add(aggregate.Id, Entry.LoadedFromDatabase(aggregate));

            AggregateIdentityHasher hasher = AggregateIdentityHasherCache.GetFor(aggregate);

            _loadedEntryHashes[aggregate.Id] = hasher.ComputeFor(aggregate);
        }
示例#2
0
        private bool RequiresCommitOperation(Entry entry)
        {
            switch (entry.State)
            {
            case EntryState.Loaded:
                AggregateIdentityHasher hasher = AggregateIdentityHasherCache.GetFor(entry.Aggregate);
                int currentHash = hasher.ComputeFor(entry.Aggregate);
                int hashOnLoad  = _loadedEntryHashes[entry.Aggregate.Id];
                return(currentHash != hashOnLoad);

            case EntryState.Added:
                return(true);

            case EntryState.Deleted:
                bool existsInDatabase = _loadedEntryHashes.ContainsKey(entry.Aggregate.Id);
                return(existsInDatabase);

            default:
                throw new ArgumentException($"'{entry.State}' is an invalid entry state type.");
            }
        }