The abstract concept of an aggregate root.
Inheritance: Ncqrs.Eventing.Sourcing.EventSource
 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);
 }
Exemple #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;
 }
        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);
            }
        }
Exemple #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);
 }
 protected override void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, UncommittedEvent evnt)
 {
     RegisterDirtyInstance(aggregateRoot);            
     _eventStream.Append(evnt);
 }
        /// <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;
 }
Exemple #10
0
 public Stage(AggregateRoot root, Sprint parent, Guid entityId, string name)
     : base(root, entityId)
 {
     _parent = parent;
     _name = name;
 }
Exemple #11
0
 private void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, UncommittedEvent evnt)
 {
     _events.Add(evnt);
 }
Exemple #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>());
 }
Exemple #13
0
 public Story(AggregateRoot parent, string description)
     : base(parent)
 {
     _description = description;
 }
Exemple #14
0
 private void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, ISourcedEvent evnt)
 {
     _events.Add(evnt);
 }
Exemple #15
0
 private void TryCreateCreateSnapshot(AggregateRoot savedInstance)
 {
     if (_snapshottingPolicy.ShouldCreateSnapshot(savedInstance))
     {
         var snapshot = _domainRepository.TryTakeSnapshot(savedInstance);
         if (snapshot != null)
         {
             _snapshotStore.SaveShapshot(snapshot);
         }
     }
 }
Exemple #16
0
 public Story(AggregateRoot parent, Sprint sprint, Guid id, string description)
     : base(parent, id)
 {
     _sprint = sprint;
     _description = description;
 }
Exemple #17
0
 public Order(AggregateRoot parent, Guid entityId)
     : base(parent, entityId)
 {
 }
Exemple #18
0
 protected override void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, UncommittedEvent evnt)
 {
     RegisterDirtyInstance(aggregateRoot);
     _eventStream.Append(evnt);
 }