Пример #1
0
        public TAggregate Get(TId id)
        {
            IAggregateRootInternal <TId> aggregate = _aggregateRootFactory.Create <TAggregate>();
            var events = _eventStore.LoadEvents(id, typeof(TAggregate), throwIfNotFound: true).ToList();

            aggregate.Load(id, events);
            return((TAggregate)aggregate);
        }
Пример #2
0
        public Task <T> FindAsync(IKey key)
        {
            Ensure.Condition.NotEmptyKey(key);

            // Try to find snapshot.
            ISnapshot snapshot = snapshotStore.Find(key);

            // If snapshot exists, load only newer events; otherwise load all of them.
            IEnumerable <EventModel> eventModels = null;

            if (snapshot == null)
            {
                eventModels = store.Get(key);
            }
            else
            {
                eventModels = store.Get(key, snapshot.Version);
            }

            IEnumerable <object> events = eventModels.Select(e => formatter.DeserializeEvent(Type.GetType(e.EventKey.Type), e.Payload));

            // If snapshot exists, create instance with it and newer events; otherwise create instance using all events.
            T instance = null;

            if (snapshot == null)
            {
                instance = factory.Create(key, events);
            }
            else
            {
                instance = factory.Create(key, snapshot, events);
            }

            // Return the aggregate.
            return(Task.FromResult(instance));
        }
Пример #3
0
 public AggregateTransaction(string identifier, IAggregateRootFactory aggregateRootFactory)
 {
     Identifier = identifier;
     Aggregate  = aggregateRootFactory.Create <TAggregateRoot>();
 }
Пример #4
0
 public TAggregateRoot CreateNew <TAggregateRoot>() where TAggregateRoot : class
 {
     return(_aggregateRootFactory.Create <TAggregateRoot>());
 }