public async Task Rename(Domain.Domains.Domain domain, string newName, CancellationToken cancellationToken) { var existing = await _domainRepository.GetByName(newName, cancellationToken); if (existing != null && existing.DomainId != domain.DomainId) { throw new DomainValidationException($"A domain named {newName} already exists."); } domain.Rename(newName); }
public async Task Add(Domain.Domains.Domain domain, CancellationToken cancellationToken) { var existing = _domainRepository.GetByName(domain.Name, cancellationToken); if (existing != null) { throw new DomainValidationException($"A domain named {domain.Name} already exists."); } await _domainRepository.Create(domain, cancellationToken); }
public async Task Create(Domain.Domains.Domain domain, CancellationToken cancellationToken) { var context = await _ddpContextProvider.Get(); var domainTable = new DomainTable { DomainId = domain.DomainId, Name = domain.Name }; await context.DomainTables.AddAsync(domainTable, cancellationToken); await _eventStore.StoreEventsFor(domain, domain.DomainId, cancellationToken); await _domainEventDispatcher.QueueEvents(domain.GetMutatingEvents()); }
public async Task <Domain.Domains.Domain> GetByName(string name, CancellationToken cancellationToken = default(CancellationToken)) { var context = await _ddpContextProvider.Get(); var domainTable = await context.DomainTables.SingleOrDefaultAsync(c => c.Name == name, cancellationToken); if (domainTable == null) { return(null); } var stream = await _eventStore.GetEventStreamFor <Domain.Domains.Domain>(domainTable.DomainId, cancellationToken : cancellationToken); var domain = new Domain.Domains.Domain(stream.DomainEvents, stream.StreamVersion); return(domain); }
public async Task <Domain.Domains.Domain> Get(Guid domainId, CancellationToken cancellationToken = default(CancellationToken)) { var context = await _ddpContextProvider.Get(); var domainTable = await context.DomainTables.FindAsync(domainId); if (domainTable == null) { return(null); } var stream = await _eventStore.GetEventStreamFor <Domain.Domains.Domain>(domainId, cancellationToken : cancellationToken); var domain = new Domain.Domains.Domain(stream.DomainEvents, stream.StreamVersion); return(domain); }
protected override async Task HandleTransacted(AddDomainCommand command, CancellationToken cancellationToken = default(CancellationToken)) { var domain = new Domain.Domains.Domain(command.DomainId, command.Name); await _domainRepository.Create(domain, cancellationToken); }