Example #1
0
        public void Intercept(IInvocation invocation)
        {
            Type type = invocation.TargetType;
            bool isOpenTransaction = true;
            var  attributes        = invocation.Method.GetCustomAttribute(typeof(TransactionAttribute), true);

            if (attributes != null)
            {
                TransactionAttribute attr = (TransactionAttribute)attributes;
                isOpenTransaction = attr.IsOpenTransaction;
            }

            if (isOpenTransaction)
            {
                using (_dbFactory.BeginTran())
                {
                    try
                    {
                        invocation.Proceed();
                        _dbFactory.CommitTran();
                    }
                    catch (Exception)
                    {
                        _dbFactory.RollbackTran();
                    }
                }
            }
            else
            {
                invocation.Proceed();
            }
        }