我很想知道如何最好地处理多个服务层之间的交易。 各个服务层利用办公室储存和检索数据库。 交易是否在个人服务层内公布和处理? 还是由另一层处理?
例如: 我有两个服务层次供用户和客户使用。 我谨:
1) Create and save a new client
2) Create and save a new user
3) Assign that user to the client
所有交易都属于单一交易。
一个简单的例子是:
$userManagementService = new UserManagementService;
$newUserData = array(...);
$newUser = $userManagementService->create($newUserData);
$clientManagementService = new ClientManagementService;
$newClientData = array(...);
$newClient = $clientManagementService->create($newClientData);
$userManagementService->assignUserToClient($newUser, $newClient);
交易逻辑在哪里?