async Task IdempotentlyCreateAgg(string id, Action <OrganizationAggregate> usingThisMethod) { var agg = await AggRepository.GetAsync <OrganizationAggregate>(id); if (agg == null) { agg = new OrganizationAggregate(new OrganizationAggregateState()); } var ov = agg.Version; usingThisMethod(agg); PublishedEvents = agg.PublishedEvents; if (ov != agg.Version) { await AggRepository.StoreAsync(agg); } }
public static async Task UpdateOutOfSession(string aggId, IAggregateRepository rep) { var agg = await rep.GetAsync <PersonAggregate>(aggId); agg.Rename(new RenamePerson() { Id = aggId, Name = "Renamed out of session" }); await rep.StoreAsync(agg); }
public static Task StoreAsync <T>(this IAggregateRepository <T> repository, T aggregate, Guid correlationId) where T : IAggregateRoot { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } if (aggregate == null) { throw new ArgumentNullException(nameof(aggregate)); } return(repository.StoreAsync(aggregate, correlationId.ToString())); }
public async Task HandleAsync(CreateProduct command) { var product = new Product(command.Title); await _repository.StoreAsync(product, command.Id); }