-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an article to explain transaction in UOW. #21994
Comments
@maliming I’ve been testing the behavior and effects of UnitOfWork over the past few days. Here, I’d like to provide some additional suggestions for the document (and also confirm and verify whether my understanding is correct). Ways to Rollback (when manually controlling UnitOfWork)When implementing complex features, it may be necessary to carefully manage the timing of rollbacks. My understanding is as follows:
Therefore, the rollback timing differs in the following two scenarios: Example 1using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
{
try
{
await _bookRepository.UpdateAsync(book);
await _productRepository.UpdateAsync(product);
await uow.CompleteAsync();
}
catch (Exception)
{
// ❗ Important ❗: If an exception occurs and enters the catch block,
// the UnitOfWork's using block has not yet ended (Dispose has not been called),
// so rollback has not been triggered yet.
// Do something when an exception is thrown
throw;
}
finally
{
// ❗ Important ❗: At this point, the UnitOfWork's using block has not yet ended (Dispose has not been called),
// so rollback has not been triggered yet.
// Do something in finally block
}
} Example 2try
{
using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
{
await _bookRepository.UpdateAsync(book);
await _productRepository.UpdateAsync(product);
await uow.CompleteAsync();
}
}
catch (Exception)
{
// If an exception occurs and enters the catch block,
// the UnitOfWork's using block has already ended (Dispose has been called),
// so rollback has already been completed.
// Do something when an exception is thrown
throw;
}
|
Thank you for reminding me, I forgot the Here is the latest article: https://github.com/abpframework/abp/blob/Understanding-Transactions-in-ABP-Unit-Of-Work/docs/en/Community-Articles/2025-01-24-Understanding-Transactions-in-ABP-Unit-Of-Work/POST.md Enjoy your commercial development, never |
Originally posted by @AlanLaiTw in #12717
The text was updated successfully, but these errors were encountered: