public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!configuration.IsValidationEnabledForControllers) { await next(); return; } using (StudioXCrossCuttingConcerns.Applying(context.Controller, StudioXCrossCuttingConcerns.Validation)) { using (var validator = iocResolver.ResolveAsDisposable <MvcActionInvocationValidator>()) { validator.Object.Initialize(context); validator.Object.Validate(); } await next(); } }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!ShouldSaveAudit(context)) { await next(); return; } using (StudioXCrossCuttingConcerns.Applying(context.Controller, StudioXCrossCuttingConcerns.Auditing)) { var auditInfo = auditingHelper.CreateAuditInfo( context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo, context.ActionArguments ); var stopwatch = Stopwatch.StartNew(); try { var result = await next(); if (result.Exception != null && !result.ExceptionHandled) { auditInfo.Exception = result.Exception; } } catch (Exception ex) { auditInfo.Exception = ex; throw; } finally { stopwatch.Stop(); auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds); await auditingHelper.SaveAsync(auditInfo); } } }