Starts in:
2 DAYS
2 HRS
33 MIN
42 SEC
Starts in:
2 D
2 H
33 M
42 S
Open Closed

Transaction Issue #8060


User avatar
0
IbrahimSarigoz created

Hello, I read this topic We need to ensure that a transaction starts when a Unit of Work (UOW) begins, with strict handling of concurrent user access. For example, in the provided code snippet, when an admin initiates a Unit of Work, other users should be forced to wait until the transaction completes.

 using (var uow = _unitOfWorkManager.Begin(requiresNew:true,isTransactional:true, isolationLevel: System.Data.IsolationLevel.ReadUncommitted))
 {
     try
     {
         MusteriNumarasiNumarator musteriNumarasiNumarator = await _musteriNumarasiNumaratorManager.CreateAsync();

         if( _currentUser.Name == "admin")
         {
            await Task.Delay(10000);
             //throw new UserFriendlyException("hata");
         }

         var gercekKisi = new GercekKisi(
          GuidGenerator.Create()
          );

         GercekKisi insertGercekKisi = await _gercekKisiRepository.InsertAsync(gercekKisi);
        
         await uow.CompleteAsync();

         return insertGercekKisi;
     }
     catch (Exception)
     {
         throw;
     }
 }

The code uses a UnitOfWorkManager to start a transactional Unit of Work with the isolation level set to ReadUncommitted. This setup ensures that the database transaction begins properly. However, we want to implement a mechanism where if the current user is "admin," the system should delay the transaction, potentially causing other users to wait. In the current state, this delay is simulated by a Task.Delay call.

How can we enforce that other users are blocked from accessing this method while the admin’s transaction is still in progress, ensuring that only one user can execute this Unit of Work at a time?

  • ABP Framework version: v8.3.0
  • UI Type: MVC
  • Database System: EF Core (Oracle)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes tiered.

1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    How can we enforce that other users are blocked from accessing this method while the admin’s transaction is still in progress, ensuring that only one user can execute this Unit of Work at a time?

    I think your problem has nothing to do with UOW. You can try to use locks/distributed locks to ensure that admin access is exclusive.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06