/// <summary> /// Loads an aggregate with the specified identifier. /// </summary> /// <typeparam name="AR">The type of the r.</typeparam> /// <param name="id">The identifier.</param> /// <returns></returns> public AR Load <AR>(IAggregateRootId id) where AR : IAggregateRoot { EventStream eventStream = eventStore.Load(id, getBoundedContext); var integrityResult = integrityPolicy.Apply(eventStream); if (integrityResult.IsIntegrityViolated) { throw new EventStreamIntegrityViolationException("asd"); } eventStream = integrityResult.Output; AR aggregateRoot; if (eventStream.TryRestoreFromHistory <AR>(out aggregateRoot) == false) { throw new AggregateLoadException("Unable to load AR with ID=" + id.Urn.Value); } return(aggregateRoot); }
/// <summary> /// Loads an aggregate with the specified identifier. /// </summary> /// <typeparam name="AR">The type of the r.</typeparam> /// <param name="id">The identifier.</param> /// <returns></returns> public ReadResult <AR> Load <AR>(IAggregateRootId id) where AR : IAggregateRoot { EventStream eventStream = eventStore.Load(id); var integrityResult = integrityPolicy.Apply(eventStream); if (integrityResult.IsIntegrityViolated) { throw new EventStreamIntegrityViolationException($"AR integrity is violated for ID={id.Urn.Value}"); } eventStream = integrityResult.Output; AR aggregateRoot; if (eventStream.TryRestoreFromHistory <AR>(out aggregateRoot) == false) { return(ReadResult <AR> .WithNotFoundHint($"Unable to load AR with ID={id.Urn.Value}")); } return(new ReadResult <AR>(aggregateRoot)); }
/// <summary> /// Loads an aggregate with the specified identifier. /// </summary> /// <typeparam name="AR">The type of the r.</typeparam> /// <param name="id">The identifier.</param> /// <returns></returns> public async Task <ReadResult <AR> > LoadAsync <AR>(IAggregateRootId id) where AR : IAggregateRoot { EventStream eventStream = await eventStore.LoadAsync(id).ConfigureAwait(false); var integrityResult = integrityPolicy.Apply(eventStream); if (integrityResult.IsIntegrityViolated) { throw new EventStreamIntegrityViolationException($"AR integrity is violated for ID={id.Value}"); } eventStream = integrityResult.Output; AR aggregateRoot; if (eventStream.TryRestoreFromHistory(out aggregateRoot) == false) // this should be a sync operation, it's just triggers internal inmemory handlers for aggregate { return(ReadResult <AR> .WithNotFoundHint($"Unable to load AR with ID={id.Value}")); } return(new ReadResult <AR>(aggregateRoot)); }