コード例 #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
        //internal static AggregateIdentityHasher GetFor<TAggregate>()
        //	=> GetFor(typeof(TAggregate));

        internal static AggregateIdentityHasher GetFor(object aggregate)
        {
            var type = aggregate.GetType();

            if (_hashersByType.TryGetValue(type, out AggregateIdentityHasher hasher))
            {
                return(hasher);
            }

            _hashersByType[type] = AggregateIdentityHasher.ResolveFor(aggregate);
            return(_hashersByType[type]);
        }
コード例 #3
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.");
            }
        }