Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
 public AggregateTransaction(string identifier, IAggregateRootFactory aggregateRootFactory)
 {
     Identifier = identifier;
     Aggregate  = aggregateRootFactory.Create <TAggregateRoot>();
 }
Exemplo n.º 4
0
 public TAggregateRoot CreateNew <TAggregateRoot>() where TAggregateRoot : class
 {
     return(_aggregateRootFactory.Create <TAggregateRoot>());
 }