コード例 #1
0
        public override async Task Befor(IAOPContext context)
        {
            _container = context.ServiceProvider.GetService <TransactionContainer>();

            if (!_container.TransactionOpened)
            {
                _container.TransactionOpened = true;
                await _container.BeginTransactionAsync(_isolationLevel);
            }
        }
コード例 #2
0
        public override async Task After(IAOPContext context)
        {
            _container = context.ServiceProvider.GetService <TransactionContainer>();

            try
            {
                if (_container.TransactionOpened)
                {
                    _container.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                _container.RollbackTransaction();
                throw new Exception("系统异常", ex);
            }

            if (_container.TransactionOpened)
            {
                _container.TransactionOpened = false;
            }

            await Task.CompletedTask;
        }