public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!context.ActionDescriptor.IsControllerAction()) { await next(); return; } var methodInfo = context.ActionDescriptor.GetMethodInfo(); var unitOfWorkAttr = UnitOfWorkHelper.GetUnitOfWorkAttributeOrNull(methodInfo); //context.HttpContext.Items["_ActionInfo"] = new ActionInfoInHttpContext //{ // IsObjectResult = context.ActionDescriptor.HasObjectResult() //}; if (unitOfWorkAttr?.IsDisabled == true) { await next(); return; } var options = CreateOptions(context, unitOfWorkAttr); var unitOfWorkManager = context.GetRequiredService <IUnitOfWorkManager>(); //Trying to begin a reserved UOW by UnitOfWorkMiddleware if (unitOfWorkManager.TryBeginReserved(UnitOfWork.UnitOfWorkReservationName, options)) { var result = await next(); if (Succeed(result)) { await SaveChangesAsync(context, unitOfWorkManager); } else { await RollbackAsync(context, unitOfWorkManager); } return; } using (var uow = unitOfWorkManager.Begin(options)) { var result = await next(); if (Succeed(result)) { await uow.CompleteAsync(context.HttpContext.RequestAborted); } else { await uow.RollbackAsync(context.HttpContext.RequestAborted); } } }
public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) { if (context.HandlerMethod == null || !context.ActionDescriptor.IsPageAction()) { await next(); return; } var methodInfo = context.HandlerMethod.MethodInfo; var unitOfWorkAttr = UnitOfWorkHelper.GetUnitOfWorkAttributeOrNull(methodInfo); context.HttpContext.Items["_AbpActionInfo"] = new AbpActionInfoInHttpContext { IsObjectResult = ActionResultHelper.IsObjectResult(context.HandlerMethod.MethodInfo.ReturnType, typeof(void)) }; if (unitOfWorkAttr?.IsDisabled == true) { await next(); return; } var options = CreateOptions(context, unitOfWorkAttr); var unitOfWorkManager = context.GetRequiredService <IUnitOfWorkManager>(); //Trying to begin a reserved UOW by AbpUnitOfWorkMiddleware if (unitOfWorkManager.TryBeginReserved(UnitOfWork.UnitOfWorkReservationName, options)) { var result = await next(); if (Succeed(result)) { await SaveChangesAsync(context, unitOfWorkManager); } else { await RollbackAsync(context, unitOfWorkManager); } return; } using (var uow = unitOfWorkManager.Begin(options)) { var result = await next(); if (Succeed(result)) { await uow.CompleteAsync(context.HttpContext.RequestAborted); } else { await uow.RollbackAsync(context.HttpContext.RequestAborted); } } }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!context.ActionDescriptor.IsControllerAction()) { await next(); return; } var methodInfo = context.ActionDescriptor.GetMethodInfo(); var unitOfWorkAttr = UnitOfWorkHelper.GetUnitOfWorkAttributeOrNull(methodInfo); context.HttpContext.Items["_AbpActionInfo"] = new AbpActionInfoInHttpContext { IsObjectResult = context.ActionDescriptor.HasObjectResult() }; if (unitOfWorkAttr?.IsDisabled == true) { await next(); return; } var options = CreateOptions(context, unitOfWorkAttr); //Trying to begin a reserved UOW by AbpUnitOfWorkMiddleware if (_unitOfWorkManager.TryBeginReserved(UnitOfWork.UnitOfWorkReservationName, options)) { var result = await next(); if (!Succeed(result)) { await RollbackAsync(context); } return; } //Begin a new, independent unit of work using (var uow = _unitOfWorkManager.Begin(options)) { var result = await next(); if (Succeed(result)) { await uow.CompleteAsync(context.HttpContext.RequestAborted); } } }
public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) { if (context.HandlerMethod == null || !context.ActionDescriptor.IsPageAction()) { await next(); return; } var methodInfo = context.HandlerMethod.MethodInfo; var unitOfWorkAttr = UnitOfWorkHelper.GetUnitOfWorkAttributeOrNull(methodInfo); context.HttpContext.Items["_PlusActionInfo"] = new PlusActionInfoInHttpContext { IsObjectResult = ActionResultHelper.IsObjectResult(context.HandlerMethod.MethodInfo.ReturnType, typeof(void)) }; if (unitOfWorkAttr?.IsDisabled == true) { await next(); return; } var options = CreateOptions(context, unitOfWorkAttr); //Trying to begin a reserved UOW by PlusUnitOfWorkMiddleware if (_unitOfWorkManager.TryBeginReserved(PlusUnitOfWorkMiddleware.UnitOfWorkReservationName, options)) { var result = await next(); if (!Succeed(result)) { await RollbackAsync(context); } return; } //Begin a new, independent unit of work using (var uow = _unitOfWorkManager.Begin(options)) { var result = await next(); if (Succeed(result)) { await uow.CompleteAsync(context.HttpContext.RequestAborted); } } }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!context.ActionDescriptor.IsControllerAction()) { await next(); } else { var methodInfo = context.ActionDescriptor.GetMethodInfo(); var unitOfWorkAttribute = UnitOfWorkHelper.GetUnitOfWorkAttributeOrNull(methodInfo); if (unitOfWorkAttribute?.IsDisabled == true) { await next(); } else//Trying to begin a reserved UOW by UnitOfWorkMiddleware { var unitOfWorkOptions = CreateOptions(context, unitOfWorkAttribute); if (_unitOfWorkManager.TryBeginReserved(UnitOfWorkMiddleware.UnitOfWorkReservationName, unitOfWorkOptions)) { var result = await next(); if (!Succeed(result)) { Rollback(); } return; } else //Begin a new, independent unit of work { using (var uow = _unitOfWorkManager.Begin(unitOfWorkOptions)) { var result = await next(); if (Succeed(result)) { await uow.CompleteAsync(context.HttpContext.RequestAborted); } } } } } }