Ejemplo n.º 1
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var method = context.HttpContext.Request.Method.ToUpper();

            if (method == "GET" || method == "HEAD" || method == "CONNECT" || method == "OPTIONS" || method == "TRACE")
            {
                await next();

                return;
            }

            logger.LogInformation($"Starting transaction for method {method}");
            await connectionFactory.BeginTransactionAsync();

            try
            {
                await next();

                logger.LogInformation("Commiting transaction");
                await connectionFactory.CommitTansactionAsync();
            }
            catch
            {
                logger.LogInformation("Rolling transaction back");
                await connectionFactory.RollbackTansactionAsync();

                throw;
            }
        }