I have an aggregate root Order with corresponding OrderService and OrderRepository.
I have an ExtendedOrder with corresponding ExtendedOrderService and ExtendedOrderRepository.
For example:
class Order {
int GetOrderId();
}
class ExtendedOrder : Order {
string GetExtendedInfo();
}
I would like to have OrderService to return both type Order and ExtendedOrder as a list of Order. But to obtain ExtendedOrder it should ask to the corresponding ExtendedOrderService when the Order is of type ExtendedOrder.
Is it possible to obtain this behavior?
Is it legal to have an aggregate root extend another aggregate root?
You don’t need an ExtendedOrderService. Just use one OrderService to coordinate results from OrderRepository and ExtendedOrderRepository.
See the answer to this question for more on the role of Application Services.
An Application Service can utilize multiple repositories.