Last active
April 20, 2021 21:15
-
-
Save ankitvijay/e4870f208e622a86f223b43728cc80d0 to your computer and use it in GitHub Desktop.
Throw Exception from relevant
This file contains 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 GetOrderQueryHandler | |
{ | |
. | |
. | |
. | |
public async Task<OrderDto> Handle(GetOrderQuery request, CancellationToken cancellationToken) | |
{ | |
var order = await _repository.Get(request.OrderId); | |
if (order == null) | |
{ | |
throw new ResourceNotFoundException($"Order with {request.OrderId} is not found"); | |
} | |
. | |
. | |
. | |
} | |
} |
This file contains 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 Order : IAggregateRoot | |
{ | |
public int OrderId { get; private set; } | |
public List<OrderItem> OrderItems { get; private set;} = new List<OrderItem>(); | |
. | |
. | |
. | |
public void ProcessOrder() | |
{ | |
if (!OrderItems.Any()) | |
{ | |
throw new DomainException("Cannot process order when no items are added"); | |
} | |
. | |
. | |
. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment