The abstract concept of an aggregate root.
Наследование: Ncqrs.Eventing.Sourcing.EventSource
Пример #1
0
 protected override void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, UncommittedEvent evnt)
 {
     var message = new EventMessage
                       {
                           Body = new StoredEvent
                                      {
                                          Body = evnt.Payload,
                                          CommitId = _commitId,
                                          EventId = evnt.EventIdentifier,
                                          MajorVersion = evnt.EventVersion.Major,
                                          MinorVersion = evnt.EventVersion.Minor,
                                          Sequence = evnt.EventSequence,
                                          TimeStamp = evnt.EventTimeStamp
                                      }
                       };
     IEventStream stream;
     var id = aggregateRoot.EventSourceId;
     if (!_trackedStreams.TryGetValue(id, out stream))
     {
         stream = _eventStore.CreateStream(id);
         _trackedStreams[id] = stream;
     }
     stream.Add(message);
     _eventStream.Append(evnt);
     _dirtyInstances.Add(aggregateRoot);
 }
 public static ISnapshotRestorer Create(AggregateRoot aggregateRoot, object snapshot)
 {
     var snapshotType = snapshot.GetType();
     if (!typeof(DynamicSnapshotBase).IsAssignableFrom(snapshotType)) throw new ArgumentException("snapshot must inherit DynamicSnapshotBase");
     var restorerType = typeof(SnapshotRestorer<>).MakeGenericType(snapshot.GetType());
     return (ISnapshotRestorer)Activator.CreateInstance(restorerType, aggregateRoot, snapshot);
 }
Пример #3
0
 public Task(AggregateRoot root, Sprint parent, Guid stageId, Guid taskId, String description)
     : base(root, taskId)
 {
     _parent = parent;
     _stageId = stageId;
     _description = description;
 }
 public bool ShouldCreateSnapshot(AggregateRoot aggregateRoot)
 {
     for (var i = aggregateRoot.InitialVersion + 1; i <= aggregateRoot.Version; i++)
     {
         if (i % _snapshotIntervalInEvents == 0)
         {
             return true;
         }
     }
     return false;
 }
Пример #5
0
        protected EntityMappedByConvention(AggregateRoot parent, Guid entityId)
            : base(parent, entityId)
        {
            var mapping = new ConventionBasedEventHandlerMappingStrategy();
            var handlers = mapping.GetEventHandlers(this);

            foreach(var directHandler in handlers)
            {
                var handler = new SourcedEventHandlerPredicate<SourcedEntityEvent>((e) => e.EntityId == this.EntityId,
                                                                                   directHandler);

                parent.RegisterHandler(handler);
            }
        }
Пример #6
0
 public void Store(AggregateRoot root, Guid commandId)
 {
     var commitAttempt = new CommitAttempt
                             {
                                 CommitId = commandId,
                                 PreviousCommitSequence = (int)root.InitialVersion,
                                 StreamRevision = (int)root.Version,
                                 StreamId = root.EventSourceId
                             };
     commitAttempt.Events.AddRange(root.GetUncommittedEvents().Select(x => new EventMessage
                                                                               {
                                                                                   Body = x
                                                                               }));
     _eventStore.Write(commitAttempt);
 }
Пример #7
0
 protected override void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, UncommittedEvent evnt)
 {
     RegisterDirtyInstance(aggregateRoot);            
     _eventStream.Append(evnt);
 }
Пример #8
0
        /// <summary>Registers the dirty instance.</summary>
        /// <param name="dirtyInstance">The dirty instance.</param>
        private void RegisterDirtyInstance(AggregateRoot dirtyInstance)
        {
            Contract.Requires<ArgumentNullException>(dirtyInstance != null, "dirtyInstance could not be null.");

            if (!_dirtyInstances.Contains(dirtyInstance))
            {
                Log.DebugFormat("Registering aggregate root {0} as dirty in unit of work {1}",
                           dirtyInstance, this);
                _dirtyInstances.Enqueue(dirtyInstance);
            }
        }
 public bool ShouldCreateSnapshot(AggregateRoot aggregateRoot)
 {
     return false;
 }
Пример #10
0
 public Stage(AggregateRoot root, Sprint parent, Guid entityId, string name)
     : base(root, entityId)
 {
     _parent = parent;
     _name = name;
 }
Пример #11
0
 private void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, UncommittedEvent evnt)
 {
     _events.Add(evnt);
 }
Пример #12
0
 public void Load(AggregateRoot root, Guid id, int? lastKnownRevision)
 {
     var stream = _eventStore.ReadUntil(id, lastKnownRevision ?? int.MaxValue);
     root.InitializeFromHistory(stream.Events.Cast<SourcedEvent>());
 }
Пример #13
0
 public Story(AggregateRoot parent, string description)
     : base(parent)
 {
     _description = description;
 }
Пример #14
0
 private void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, ISourcedEvent evnt)
 {
     _events.Add(evnt);
 }
Пример #15
0
 private void TryCreateCreateSnapshot(AggregateRoot savedInstance)
 {
     if (_snapshottingPolicy.ShouldCreateSnapshot(savedInstance))
     {
         var snapshot = _domainRepository.TryTakeSnapshot(savedInstance);
         if (snapshot != null)
         {
             _snapshotStore.SaveShapshot(snapshot);
         }
     }
 }
Пример #16
0
 public Story(AggregateRoot parent, Sprint sprint, Guid id, string description)
     : base(parent, id)
 {
     _sprint = sprint;
     _description = description;
 }
Пример #17
0
 public Order(AggregateRoot parent, Guid entityId)
     : base(parent, entityId)
 {
 }
Пример #18
0
 protected override void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, UncommittedEvent evnt)
 {
     RegisterDirtyInstance(aggregateRoot);
     _eventStream.Append(evnt);
 }