Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

Bloco de código
languagec#
firstline1
titleRegistrationService.cs
linenumberstrue
using Tnf.Architecture.Domain.Events;
using Tnf.Architecture.Domain.Interfaces.Services;
using Tnf.App.Domain.Services;
using Tnf.Dto;
using Tnf.Events.Bus;

namespace Tnf.Architecture.Domain.Registration
{
    public class RegistrationService : DomainService<IPersonRepository>AppDomainService<IPersonRepository>, IRegistrationService
    {
        private readonly IEventBus _eventBus;
        public RegistrationService(IPersonRepository repository, IEventBus eventBus)
            : base(repository)
        {
            _eventBus = eventBus;
        }

        public DtoResponseBase<PersonDto>PersonDto Register(PersonDto dto)
        {
            var response = new DtoResponseBase<PersonDto>();
            var builder = new PersonBuilder()
                   .WithName(dto.Name);
 
            var buildperson = builder.Build();
            if (!buildNotification.SuccessHasNotification())
            {
                response.AddNotifications(build.Notificationsvar id = Repository.CreatePerson(person);
                return response;
            }

            var id = Repository.CreatePerson(dto)dto.Id = id;
            dto.Id = id;}

            // Trigger event before create person
            _eventBus.Trigger(new NewRegistrationEventData(dto));
            return responsedto;
        }
    }
}

Observe que após o objeto de domínio ser construído e estar valido, o repositório é consumido cadastrando um novo dado, fazendo o disparo do evento através da interface IEventBus injetada em nosso serviço de domínio.

...