...
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
// Domain service interface public interface IWhiteHouseService : IDomainService { Task<DtoResponseBase<PresidentDto>> InsertPresidentAsync(PresidentDto request); } // Domain service public class WhiteHouseService : DomainService<IWhiteHouseRepository>, IWhiteHouseService { private readonly IEventBus _eventBus; public WhiteHouseService(IWhiteHouseRepository repository, IEventBus eventBus) : base(repository) { _eventBus = eventBus; } public Task<DtoResponseBase<PresidentDto>> InsertPresidentAsync(PresidentDto request) { var response = new DtoResponseBase<PresidentDto>(); var builder = new PresidentBuilder() .WithId(item.Id) .WithName(item.Name); var build = builder.Build(); if (!build.Success) { response.AddNotifications(build.Notifications); return response; } var presidentCreated = await Repository.InsertPresidentAsync(presidentsrequest); response.Data = presidentCreated; // Trigger event _eventBus.Trigger(new PresidentCreatedEvent(presidentCreated)); return response; } } |
...