I have service which is getting domain from repository and passing its own instance to the domain for some external dependency. Can it become anti pattern? RichDomainModel
suggests to pass dependency to domain as required, however I am concerned if this can be called as cyclic dependency and would become anti pattern?
class Order
{
private $currencyVal;
public function __construct()
{
}
public function processBusinessLogic($arg1, $arg2)
{
// do some business logic operation on $arg1, $arg2 & $this->currencyVal
}
public function populateExternalValue(OrderService $service)
{
$this->currencyVal = $service->getCurrencyValue($this);
}
}
OrderService
{
private $orderRepository;
private $externalServiceClient;
public function __construct(OrderRepository $orderRepository, Client $externalServiceClient)
{
$this->orderRepository = $orderRepository;
$this->externalServiceClient = $externalServiceClient;
}
public function processDomain(Request $request)
{
$order = $this->orderRepository->findById($request->orderId);
$order->populateExternalValue($this);
$order->processBusinessLogic($request->arg1, $request->arg2);
$this->orderRepository->save($order);
}
public function getCurrencyValue(Order $order)
{
return $this->externalServiceClient->getValue($order->currency)
}
}
Alternatively I could use something like this but that would lead to AnemicDomainModel
$order->setCurrencyValue($this->getCurrencyValue($order));
Thoughts?