Ejemplo n.º 1
0
        public void Add <T>(T aggregate) where T : class, TBase
        {
            if (aggregates.ContainsKey(aggregate.Id))
            {
                throw new ArgumentException($"Duplicate aggregate root with ID '{aggregate.Id}' and type '{typeof(T).FullName}'");
            }

            aggregates.Add(aggregate.Id, aggregate);
            Guid classId = entityTypeManager.GetClassInfoByClrType(aggregate.GetType()).Id;

            eventStore.AddStream(aggregate.Id);
            eventStore.SetStreamMetadata(aggregate.Id,
                                         new Dictionary <string, string>()
            {
                { AggregateEventStreamMetadataNames.ClassId, classId.ToString() }
            });
        }
Ejemplo n.º 2
0
        public void Add <T>(T aggregate) where T : class, IAggregateRoot
        {
            var esAggregate = GetEventSourcedAggregate(aggregate);

            if (aggregates.TryGetValue(aggregate.Id, out var existing))
            {
                if (existing == aggregate)
                {
                    return;
                }

                throw new ArgumentException($"Duplicate aggregate root with ID '{aggregate.Id}' and type '{typeof(T).FullName}'");
            }

            aggregates.Add(aggregate.Id, esAggregate);
            Guid classId = entityTypeManager.GetClassInfoByClrType(aggregate.GetType()).Id;

            eventStore.AddStream(aggregate.Id);
            eventStore.SetStreamMetadata(aggregate.Id,
                                         new Dictionary <string, string>()
            {
                { AggregateEventStreamMetadataNames.ClassId, classId.ToString() }
            });
        }