Answer the question
In order to leave comments, you need to log in
Is it possible to use services in rich models?
The main question is, can I use classes from the service layer through DI in rich models, while changing the state of the model only inside the object? If not, and you still need to write absolutely all the logic in the model object, then it will become just a god object with 100500 lines, and this is not good, or ideally, the service layer with rich models should be minimal (for example, only for sending email, etc. .) and not affect the domain logic? Thanks in advance for your replies
Answer the question
In order to leave comments, you need to log in
a? If not, and you still need to write absolutely all the logic in the model object, then it will simply become a god object with 100500 lines
final class HandleCheckOutShoppingCart
{
public function __construct(Carts $carts, PaymentGateway $gateway)
{
$this->carts = $carts;
$this->gateway = $gateway;
}
public function __invoke(CheckOutShoppingCart $command) : void
{
$shoppingCart = $this->carts->get($command->shoppingCart());
$payment = $this->gateway->captureCharge($command->charge());
$shoppingCart->checkOut($payment);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question