public virtual async Task InvokeAsync() { var cacheEntry = _controllerActionInvokerCache.GetCacheEntry(Context); _filters = _controllerActionInvokerCache.GetFiltersFromEntry(cacheEntry, Context); _controllerActionMethodExecutor = cacheEntry.ActionMethodExecutor; _cursor = new FilterCursor(_filters); Context.ModelState.MaxAllowedErrors = _maxModelValidationErrors; await InvokeAllAuthorizationFiltersAsync(); // If Authorization Filters return a result, it's a short circuit because // authorization failed. We don't execute Result Filters around the result. Debug.Assert(_authorizationContext != null); if (_authorizationContext.Result != null) { await InvokeResultAsync(_authorizationContext.Result); return; } try { await InvokeAllResourceFiltersAsync(); } finally { // Release the instance after all filters have run. We don't need to surround // Authorizations filters because the instance will be created much later than // that. if (Instance != null) { ReleaseInstance(Instance); } } // We've reached the end of resource filters. If there's an unhandled exception on the context then // it should be thrown and middleware has a chance to handle it. Debug.Assert(_resourceExecutedContext != null); if (_resourceExecutedContext.Exception != null && !_resourceExecutedContext.ExceptionHandled) { if (_resourceExecutedContext.ExceptionDispatchInfo == null) { throw _resourceExecutedContext.Exception; } else { _resourceExecutedContext.ExceptionDispatchInfo.Throw(); } } }
public ResourceInvoker( DiagnosticSource diagnosticSource, ILogger logger, ActionContext actionContext, IFilterMetadata[] filters, IList <IValueProviderFactory> valueProviderFactories) { _diagnosticSource = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _actionContext = actionContext ?? throw new ArgumentNullException(nameof(actionContext)); _filters = filters ?? throw new ArgumentNullException(nameof(filters)); _valueProviderFactories = valueProviderFactories ?? throw new ArgumentNullException(nameof(valueProviderFactories)); _cursor = new FilterCursor(filters); }
public ControllerActionInvoker( ControllerActionInvokerCache cache, IControllerFactory controllerFactory, IControllerArgumentBinder controllerArgumentBinder, ILogger logger, DiagnosticSource diagnosticSource, ActionContext actionContext, IReadOnlyList <IValueProviderFactory> valueProviderFactories, int maxModelValidationErrors) { if (cache == null) { throw new ArgumentNullException(nameof(cache)); } if (controllerFactory == null) { throw new ArgumentNullException(nameof(controllerFactory)); } if (controllerArgumentBinder == null) { throw new ArgumentNullException(nameof(controllerArgumentBinder)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (diagnosticSource == null) { throw new ArgumentNullException(nameof(diagnosticSource)); } if (actionContext == null) { throw new ArgumentNullException(nameof(actionContext)); } if (valueProviderFactories == null) { throw new ArgumentNullException(nameof(valueProviderFactories)); } _controllerFactory = controllerFactory; _controllerArgumentBinder = controllerArgumentBinder; _logger = logger; _diagnosticSource = diagnosticSource; _controllerContext = new ControllerContext(actionContext); _controllerContext.ModelState.MaxAllowedErrors = maxModelValidationErrors; // PERF: These are rarely going to be changed, so let's go copy-on-write. _controllerContext.ValueProviderFactories = new CopyOnWriteList <IValueProviderFactory>(valueProviderFactories); var cacheEntry = cache.GetState(_controllerContext); _filters = cacheEntry.Filters; _executor = cacheEntry.ActionMethodExecutor; _cursor = new FilterCursor(_filters); }