Answer the question
In order to leave comments, you need to log in
DDD Transactions in Application Service?
Good afternoon, I'm not an expert in DDD and I don't understand all the subtleties, please tell me how the launch of transactions is implemented in the Application Service?
There is a structure:
src-
- Module1
- Application
- BooService
- FooService
- Domain
- Repository
- MyModelRepositoryInterface
- Infrastructure
- ExampleCommand
- Repository
- MyModelRepository
- Module2
- Application
- Domain
- Infrastructure
class BooService
{
public function execute()
{
//Transaction start
$result = $this->fooService->execute();
$this->myModelRepository->add(new MyModel($result->foo, $result->boo));
//Transaction finish
return true;
}
}
Answer the question
In order to leave comments, you need to log in
Transactions are the level of infrastructure
"with an interface in the Domain", the domain should not know anything about transactions.
It is possible to propose such a solution
Application
$repository->transactional(
static function () use (
$repository
) {
$repository->save($entity);
//и прочее сохранение данных
}
);
public function transactional(\closure $func)
{
$db_connection = getDbConnection();
$db_connection->startTransaction();
$func();
$db_connection->commitTransaction();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question