To persist entity changes, your application services and controllers will require Cycle\ORM\EntityManagerInterface.
By default, the framework will automatically create a transaction on-demand from the container. Considering that
transactions always clean after the run operation, you can request it as a constructor parameter.
use Cycle\ORM\EntityManagerInterface;
class MyService
{
private EntityManagerInterface $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
}
Note
Make sure thatpersist/deleteandrunmethods are always called within one method scope while using service-specific transactions.
You can always test the service by mocking Cycle\ORM\EntityManagerInterface, consider binding mocked transaction
object to your application instance to see what is being persisted.
Note
Read more how to use Create, Update and Delete entities here.