/// <summary>
        /// Gets the by ID.
        /// </summary>
        /// <typeparam name="TAggregateRoot">The type of the aggregate root.</typeparam>
        /// <param name="aggregateID">The aggregate ID.</param>
        /// <param name="queryOptions">The query options.</param>
        /// <returns></returns>
        public TAggregateRoot GetByID <TAggregateRoot>(object aggregateID, AggregateRootQueryOptions queryOptions)
            where TAggregateRoot : AggregateRoot
        {
            if (aggregateID == null)
            {
                throw new ArgumentNullException("aggregateID");
            }
            var aggregate = (_factory(typeof(TAggregateRoot)) as TAggregateRoot);

            if (aggregate == null)
            {
                throw new InvalidOperationException("aggregate");
            }
            // find snapshot
            var loaded = false;
            AggregateRootSnapshot snapshot = null;

            if (_snapshotStore != null)
            {
                var snapshoter = (aggregate as ICanAggregateRootSnapshot);
                if (snapshoter != null && (snapshot = _snapshotStore.GetLatestSnapshot <TAggregateRoot>(aggregateID)) != null)
                {
                    loaded = true;
                    snapshoter.LoadSnapshot(snapshot);
                }
            }
            // load events
            var events = _eventStore.GetEventsByID(aggregateID, (snapshot != null ? snapshot.LastEventSequence : 0));

            loaded |= ((IAggregateRootStateAccessor)aggregate).LoadFromHistory(events);
            return((queryOptions & AggregateRootQueryOptions.UseNullAggregates) == 0 ? aggregate : (loaded ? aggregate : null));
        }
 /// <summary>
 /// Gets the many by I ds.
 /// </summary>
 /// <typeparam name="TAggregateRoot">The type of the aggregate root.</typeparam>
 /// <param name="aggregateIDs">The aggregate I ds.</param>
 /// <param name="queryOptions">The query options.</param>
 /// <returns></returns>
 public IEnumerable <TAggregateRoot> GetManyByIDs <TAggregateRoot>(IEnumerable <object> aggregateIDs, AggregateRootQueryOptions queryOptions)
     where TAggregateRoot : AggregateRoot
 {
     if (aggregateIDs == null)
     {
         throw new ArgumentNullException("aggregateIDs");
     }
     return(aggregateIDs.Select(x => GetByID <TAggregateRoot>(x, queryOptions)).ToList());
 }
 /// <summary>
 /// Gets the many by I ds.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <param name="aggregateIDs">The aggregate I ds.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 /// <param name="queryOptions">The query options.</param>
 /// <returns></returns>
 public static IEnumerable <AggregateRoot> GetManyByIDs(this IAggregateRootRepository repository, IEnumerable <object> aggregateIDs, Type aggregateType, AggregateRootQueryOptions queryOptions)
 {
     return(repository.GetManyByIDs <AggregateRoot>(aggregateIDs, queryOptions));
 }
 /// <summary>
 /// Gets the by ID.
 /// </summary>
 /// <param name="repository">The repository.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 /// <param name="aggregateID">The aggregate ID.</param>
 /// <param name="queryOptions">The query options.</param>
 /// <returns></returns>
 public static AggregateRoot GetByID(this IAggregateRootRepository repository, Type aggregateType, object aggregateID, AggregateRootQueryOptions queryOptions)
 {
     return(repository.GetByID <AggregateRoot>(aggregateID, queryOptions));
 }