Last active
September 24, 2019 21:41
-
-
Save wellingtonjhn/3be2dd6b2b4a6ffade6180a36ec762fd to your computer and use it in GitHub Desktop.
Handler with NotificationContext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CreateCustomerHandler : IRequestHandler<CreateCustomer, Guid> | |
| { | |
| private readonly NotificationContext _notificationContext; | |
| private readonly ICustomerRepository _customerRepository; | |
| public CreateCustomerHandler( | |
| NotificationContext notificationContext, | |
| ICustomerRepository customerRepository) | |
| { | |
| _notificationContext = notificationContext; | |
| _customerRepository = customerRepository; | |
| } | |
| public async Task<Guid> Handle(CreateCustomer request, CancellationToken cancellationToken) | |
| { | |
| var customer = new Customer(request.Name, request.Email); | |
| if (customer.Invalid) | |
| { | |
| _notificationContext.AddNotifications(customer.ValidationResult); | |
| return Guid.Empty; | |
| } | |
| await _customerRepository.Save(customer); | |
| return customer.Id; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment