コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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()));
        }
コード例 #4
0
 public async Task HandleAsync(CreateProduct command)
 {
     var product = new Product(command.Title);
     await _repository.StoreAsync(product, command.Id);
 }