Created
July 15, 2019 08:15
-
-
Save ducmeit1/15bb9015dfc1b05202ca347d9b17cf0a to your computer and use it in GitHub Desktop.
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
| using System; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using Customer.Data.IRepositories; | |
| using Customer.Domain.Events; | |
| using MediatR; | |
| using Microsoft.Extensions.Logging; | |
| namespace Customer.Service.Subcribers | |
| { | |
| public class CustomerCreatedHandler : INotificationHandler<CustomerCreatedEvent> | |
| { | |
| private readonly ICustomerRepository _customerRepository; | |
| private readonly ILogger _logger; | |
| public CustomerCreatedHandler(ICustomerRepository customerRepository, ILogger<CustomerCreatedHandler> logger) | |
| { | |
| _customerRepository = customerRepository ?? throw new ArgumentNullException(nameof(customerRepository)); | |
| _logger = logger; | |
| } | |
| public async Task Handle(CustomerCreatedEvent notification, CancellationToken cancellationToken) | |
| { | |
| var customer = await _customerRepository.GetAsync(e => e.Id == notification.CustomerId); | |
| if (customer == null) | |
| { | |
| //TODO: Handle next business logic if customer is not found | |
| _logger.LogWarning("Customer is not found by customer id from publisher"); | |
| } | |
| else | |
| { | |
| _logger.LogInformation($"Customer has found by customer id: {notification.CustomerId} from publisher"); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment