/// <summary> /// Find (rehydrate) an account aggregate. /// </summary> /// <param name="id">Account Id</param> /// <param name="unitOfWork">Unit of work</param> /// <returns>Rehydrated aggregate</returns> /// <remarks>TODO: Could it happen that there are new events for the aggregate that are not on the aggregate in our unit of work?</remarks> public Account Find(Guid id, IAggregateUnitOfWork unitOfWork) { // This assumes that the aggregate in the unit of work is up-to-date var fromUnitOfWork = unitOfWork.Get<Account>(id); if (fromUnitOfWork != null) { return fromUnitOfWork; } var newAccount = new Account(id, this.eventStore.GetEventsFor(id)); unitOfWork.Register(newAccount); return newAccount; }
/// <summary> /// Find (rehydrate) an account aggregate. /// </summary> /// <param name="id">Account Id</param> /// <param name="unitOfWork">Unit of work</param> /// <returns>Rehydrated aggregate</returns> /// <remarks>TODO: Could it happen that there are new events for the aggregate that are not on the aggregate in our unit of work?</remarks> public Account Find(Guid id, IAggregateUnitOfWork unitOfWork) { // This assumes that the aggregate in the unit of work is up-to-date var fromUnitOfWork = unitOfWork.Get <Account>(id); if (fromUnitOfWork != null) { return(fromUnitOfWork); } var newAccount = new Account(id, this.eventStore.GetEventsFor(id)); unitOfWork.Register(newAccount); return(newAccount); }
/// <summary> /// Save the (new) account (in the unit of work) /// </summary> /// <param name="account">Account to save</param> /// <param name="unitOfWork">Unit of work to use</param> public void Save(Account account, IAggregateUnitOfWork unitOfWork) { unitOfWork.Register(account); }