Supose I have an order entity and I want to can delete it only if this order has no order items.
In this case, when I implement the repository pattern, I need a method that allows to delete entities. So the consumer (for example a controller in ASP), would do it in this way:
var order = unitOfWork.Orthers.GetOrderById(1);
unitOfWork.Orders.Remove(order);
unitOfWork.Complete();
The problem here is that the consumer delete always the order, and don't check if it is possible or not. Anyway, the domain has no control or has no the way to forbid to the consumer to delete an order if it is not allowed.
There is some way to enforce that the consumer wouldn't be the responsable to ensure that it is possible to delete the order?
In the rest of the uses case, for example to create an order, the constructor ensure the information is correct, and in the update, the order only allow to update if it is possible according to the rules. But in the case to delete an order, I don't know how to do it.
Thanks.