-
Notifications
You must be signed in to change notification settings - Fork 42
almin: Transaction of UseCase #219
Copy link
Copy link
Closed
Labels
Description
It related with Unit of work #186
Almin's unit of work is a single of UseCase lifecycle.
We will introduce the Unit of work as actual class.
illustration code:
context.transaction(unitOfWork => { // begin transaction
const executor = new UseCaseExecutor(useCase);
executor.onDispatch(() => unitOfWork.commit()); // store group receive it and try to commit
executor.onDidExecuted(() => unitOfWork.commit()); // store group receive it and try to commit
executor.onCompleteExecuted(() => unitOfWork.commit()); // store group receive it and try to commit
return executor.execute(); // may be returned a promise
}).then(() => {
// end transation
});What is make it ?
- Transaction of UseCase
- The user can prevent heavy updating of StoreGroup
- Silent UseCase
- e.g.)
LogUseCasewont to update any Store, but currenly it dispatchdidExecutedandcompleteExected
- e.g.)
illustration code
Transaction UseCase that can do manually update.
It help to improve application performance.
Context.useCase#exceutetry to commit: 2- Manually transation try to commit: 1
context.transaction(unitOfWork => { // begin transaction
return context.useCase(new UseCase).execute().then(() => {
unitOfWork.commit(); // => try to change StoreGroup
})
}).then(() => { // automatically release transaction - almin not want to get dead lock.
// after transaction
});Example
Difference with Context#useCase:
- Do not update StoreGroup automatically
- You should call
committer.commit()to update StoreGroup at any time
Example code:
context.transaction("name", transactionContext => {
return transactionContext.useCase(new ChangeAUseCase()).execute() // no update store
.then(() => {
return transactionContext.useCase(new ChangeBUseCase()).execute(); // no update store
}).then(() => {
return transactionContext.useCase(new ChangeCUseCase()).execute(); // no update store
}).then(() => {
transactionContext.commit(); // update store
// replay: ChangeAUseCase -> ChangeBUseCase -> ChangeCUseCase
});
})FAQ
- Q. Why automatically release the transation
- A. Almin do not dead lock
- Q. Why the transaction prevent to update each Stores.
- A. Almin apply CQRS.
- CQRS apply Eventual consistency
- The view of application only know updating of StoreGroup
- In other word, the view don't know updating of each Stores
- The transaction aim to stop updating of StoreGroup
- In other word, the transation aim to improve the view performance
- Q. Can Child UseCase context use transaction?
- A. No. The transaction handle a root UseCase. The root UseCase includes children UseCase.
- Child UseCase context is under the root transaction
Reactions are currently unavailable
