Abp: BeginTransactional method for UnitOfWorkManagerExtensions

Created on 5 Jan 2020  路  2Comments  路  Source: abpframework/abp

For now when I want to begin a transactional uow, I need this code:

            using (var uow = _unitOfWorkManager.Begin(new AbpUnitOfWorkOptions
            {
                IsTransactional = true
            }))
            {
            }

It doesn't look simple enough.

I have two ways for this problem:

  1. Adding a method BeginTransactional():
        public static IUnitOfWork Begin([NotNull] this IUnitOfWorkManager unitOfWorkManager, bool requiresNew = false)
        {
            Check.NotNull(unitOfWorkManager, nameof(unitOfWorkManager));

            return unitOfWorkManager.Begin(new AbpUnitOfWorkOptions(), requiresNew);
        }

        public static IUnitOfWork BeginTransactional([NotNull] this IUnitOfWorkManager unitOfWorkManager, bool requiresNew = false)
        {
            Check.NotNull(unitOfWorkManager, nameof(unitOfWorkManager));

            return unitOfWorkManager.Begin(new AbpUnitOfWorkOptions {IsTransactional = true}, requiresNew);
        }
  1. Let uow manager care the request type and provide correct default value for IsTransactional.

If you let ABP to handle it, ABP disables transaction for GET, enables for POST, PUT and others.

It will reduce the chance of setting IsTransactional manually.

What do you think? @hikalkan

Most helpful comment

Or you can add an IsTransactionalparameter to the Beginmethod, which defaults to false.

public static IUnitOfWork Begin([NotNull] this IUnitOfWorkManager unitOfWorkManager, 
   bool requiresNew = false, 
   bool isTransactional = false)
{

}

All 2 comments

Or you can add an IsTransactionalparameter to the Beginmethod, which defaults to false.

public static IUnitOfWork Begin([NotNull] this IUnitOfWorkManager unitOfWorkManager, 
   bool requiresNew = false, 
   bool isTransactional = false)
{

}
Was this page helpful?
0 / 5 - 0 ratings