Exemplo n.º 1
0
 public override ValueTask <IActionResult> Execute(
     IActionResultTypeMapper mapper,
     ObjectMethodExecutor executor,
     object controller,
     object?[]?arguments)
 {
     executor.Execute(controller, arguments);
     return(new ValueTask <IActionResult>(new EmptyResult()));
 }
Exemplo n.º 2
0
 public ApiResponseTypeProvider(
     IModelMetadataProvider modelMetadataProvider,
     IActionResultTypeMapper mapper,
     MvcOptions mvcOptions)
 {
     _modelMetadataProvider = modelMetadataProvider;
     _mapper     = mapper;
     _mvcOptions = mvcOptions;
 }
Exemplo n.º 3
0
 public ControllerRequestDelegateFactory(
     ControllerActionInvokerCache controllerActionInvokerCache,
     IOptions <MvcOptions> optionsAccessor,
     ILoggerFactory loggerFactory,
     DiagnosticListener diagnosticListener,
     IActionResultTypeMapper mapper)
     : this(controllerActionInvokerCache, optionsAccessor, loggerFactory, diagnosticListener, mapper, null)
 {
 }
 public override async ValueTask <IActionResult> Execute(
     IActionResultTypeMapper mapper,
     ObjectMethodExecutor executor,
     object controller,
     object[] arguments)
 {
     await(Task) executor.Execute(controller, arguments);
     return(new EmptyResult());
 }
Exemplo n.º 5
0
 public override ValueTask <IActionResult> Execute(
     ActionContext actionContext,
     IActionResultTypeMapper mapper,
     ObjectMethodExecutor executor,
     object controller,
     object?[]?arguments)
 {
     executor.Execute(controller, arguments);
     return(new(EmptyResultInstance));
 }
 /// <summary>
 /// Creates a new instance of <see cref="DefaultApiDescriptionProvider"/>.
 /// </summary>
 /// <param name="optionsAccessor">The accessor for <see cref="MvcOptions"/>.</param>
 /// <param name="constraintResolver">The <see cref="IInlineConstraintResolver"/> used for resolving inline
 /// constraints.</param>
 /// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
 /// <param name="mapper"> The <see cref="IActionResultTypeMapper"/>.</param>
 public DefaultApiDescriptionProvider(
     IOptions <MvcOptions> optionsAccessor,
     IInlineConstraintResolver constraintResolver,
     IModelMetadataProvider modelMetadataProvider,
     IActionResultTypeMapper mapper)
 {
     _mvcOptions            = optionsAccessor.Value;
     _constraintResolver    = constraintResolver;
     _modelMetadataProvider = modelMetadataProvider;
     _mapper = mapper;
 }
Exemplo n.º 7
0
        private IActionResult ConvertToActionResult(IActionResultTypeMapper mapper, object returnValue, Type declaredType)
        {
            var result = (returnValue as IActionResult) ?? mapper.Convert(returnValue, declaredType);

            if (result == null)
            {
                throw new InvalidOperationException();
            }

            return(result);
        }
        private IActionResult ConvertToActionResult(IActionResultTypeMapper mapper, object returnValue, Type declaredType)
        {
            var result = (returnValue as IActionResult) ?? mapper.Convert(returnValue, declaredType);

            if (result == null)
            {
                throw new InvalidOperationException(Resources.FormatActionResult_ActionReturnValueCannotBeNull(declaredType));
            }

            return(result);
        }
Exemplo n.º 9
0
            public override ValueTask <IActionResult> Execute(
                IActionResultTypeMapper mapper,
                TestSkillionObjectMethodExecutor executor,
                object controller,
                object[] arguments)
            {
                var returnValue  = executor.Execute(controller, arguments);
                var actionResult = ConvertToActionResult(mapper, returnValue, executor.MethodReturnType);

                return(new ValueTask <IActionResult>(actionResult));
            }
Exemplo n.º 10
0
        public override async ValueTask <IActionResult> Execute(
            ActionContext actionContext,
            IActionResultTypeMapper mapper,
            ObjectMethodExecutor executor,
            object controller,
            object?[]?arguments)
        {
            var context = new ControllerEndpointFilterInvocationContext(_controllerActionDescriptor, actionContext, executor, mapper, controller, arguments);
            var result  = await _controllerActionDescriptor.FilterDelegate !(context);

            return(ConvertToActionResult(mapper, result, executor.IsMethodAsync ? executor.AsyncResultType ! : executor.MethodReturnType));
        }
            public override ValueTask <IActionResult> Execute(
                IActionResultTypeMapper mapper,
                ObjectMethodExecutor executor,
                object controller,
                object[] arguments)
            {
                // Sync method returning arbitrary object
                var returnValue  = executor.Execute(controller, arguments);
                var actionResult = ConvertToActionResult(mapper, returnValue, executor.MethodReturnType);

                return(new ValueTask <IActionResult>(actionResult));
            }
 public ClownFishWebActionInvokerProvider(
     ControllerActionInvokerCache controllerActionInvokerCache,
     IOptions <MvcOptions> optionsAccessor,
     DiagnosticSource diagnosticSource,
     IActionResultTypeMapper mapper)
 {
     this._controllerActionInvokerCache = controllerActionInvokerCache;
     this._valueProviderFactories       = (IReadOnlyList <IValueProviderFactory>)optionsAccessor.Value.ValueProviderFactories.ToArray <IValueProviderFactory>();
     this._maxModelValidationErrors     = optionsAccessor.Value.MaxModelValidationErrors;
     this._diagnosticSource             = diagnosticSource;
     this._mapper = mapper;
 }
            public override ValueTask <IActionResult> Execute(
                IActionResultTypeMapper mapper,
                ObjectMethodExecutor executor,
                object controller,
                object[] arguments)
            {
                var actionResult = (IActionResult)executor.Execute(controller, arguments);

                EnsureActionResultNotNull(executor, actionResult);

                return(new ValueTask <IActionResult>(actionResult));
            }
 /// <summary>
 /// Creates a new instance of <see cref="DefaultApiDescriptionProvider"/>.
 /// </summary>
 /// <param name="optionsAccessor">The accessor for <see cref="MvcOptions"/>.</param>
 /// <param name="constraintResolver">The <see cref="IInlineConstraintResolver"/> used for resolving inline
 /// constraints.</param>
 /// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
 /// <param name="mapper">The <see cref="IActionResultTypeMapper"/>.</param>
 /// <param name="routeOptions">The accessor for <see cref="RouteOptions"/>.</param>
 /// <remarks>The <paramref name="mapper"/> parameter is currently ignored.</remarks>
 public DefaultApiDescriptionProvider(
     IOptions <MvcOptions> optionsAccessor,
     IInlineConstraintResolver constraintResolver,
     IModelMetadataProvider modelMetadataProvider,
     IActionResultTypeMapper mapper,
     IOptions <RouteOptions> routeOptions)
 {
     _mvcOptions            = optionsAccessor.Value;
     _constraintResolver    = constraintResolver;
     _modelMetadataProvider = modelMetadataProvider;
     _responseTypeProvider  = new ApiResponseTypeProvider(modelMetadataProvider, mapper, _mvcOptions);
     _routeOptions          = routeOptions.Value;
 }
            public override async ValueTask <IActionResult> Execute(
                IActionResultTypeMapper mapper,
                ObjectMethodExecutor executor,
                object controller,
                object[] arguments)
            {
                // Async method returning awaitable-of-nonvoid
                var returnValue = await executor.ExecuteAsync(controller, arguments);

                var actionResult = ConvertToActionResult(mapper, returnValue, executor.AsyncResultType);

                return(actionResult);
            }
            public override async ValueTask <IActionResult> Execute(
                IActionResultTypeMapper mapper,
                ObjectMethodExecutor executor,
                object controller,
                object[] arguments)
            {
                // Async method returning awaitable-of-IActionResult (e.g., Task<ViewResult>)
                // We have to use ExecuteAsync because we don't know the awaitable's type at compile time.
                var actionResult = (IActionResult)await executor.ExecuteAsync(controller, arguments);

                EnsureActionResultNotNull(executor, actionResult);
                return(actionResult);
            }
Exemplo n.º 17
0
 public PageRequestDelegateFactory(
     PageActionInvokerCache cache,
     IModelMetadataProvider modelMetadataProvider,
     ITempDataDictionaryFactory tempDataFactory,
     IOptions <MvcOptions> mvcOptions,
     IOptions <MvcViewOptions> mvcViewOptions,
     IPageHandlerMethodSelector selector,
     DiagnosticListener diagnosticListener,
     ILoggerFactory loggerFactory,
     IActionResultTypeMapper mapper)
     : this(cache, modelMetadataProvider, tempDataFactory, mvcOptions, mvcViewOptions, selector, diagnosticListener, loggerFactory, mapper, null)
 {
 }
Exemplo n.º 18
0
        public ModelBindingActionInvoker(
            ILogger logger,
            DiagnosticListener diagnosticListener,
            IActionResultTypeMapper mapper,
            ControllerContext controllerContext,
            ControllerActionInvokerCacheEntry cacheEntry,
            IFilterMetadata[] filters)
            : base(diagnosticListener, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories)
        {
            CommonValidator.CheckForNullReference(cacheEntry, nameof(cacheEntry));

            this.cacheEntry        = cacheEntry;
            this.controllerContext = controllerContext;
        }
 public ModelBindingActionInvokerFactory(
     ControllerActionInvokerCache controllerActionInvokerCache,
     IOptions <MvcOptions> optionsAccessor,
     ILoggerFactory loggerFactory,
     DiagnosticListener diagnosticListener,
     IActionResultTypeMapper mapper)
 {
     this.controllerActionInvokerCache = controllerActionInvokerCache;
     this.valueProviderFactories       = optionsAccessor.Value.ValueProviderFactories.ToArray();
     this.maxModelValidationErrors     = optionsAccessor.Value.MaxModelValidationErrors;
     this.logger             = loggerFactory.CreateLogger <ControllerActionInvoker>();
     this.diagnosticListener = diagnosticListener;
     this.mapper             = mapper;
 }
 public ControllerActionInvokerProvider(
     ControllerActionInvokerCache controllerActionInvokerCache,
     IOptions <MvcOptions> optionsAccessor,
     ILoggerFactory loggerFactory,
     DiagnosticSource diagnosticSource,
     IActionResultTypeMapper mapper)
 {
     _controllerActionInvokerCache = controllerActionInvokerCache;
     _valueProviderFactories       = optionsAccessor.Value.ValueProviderFactories.ToArray();
     _maxModelValidationErrors     = optionsAccessor.Value.MaxModelValidationErrors;
     _logger           = loggerFactory.CreateLogger <ControllerActionInvoker>();
     _diagnosticSource = diagnosticSource;
     _mapper           = mapper;
 }
Exemplo n.º 21
0
 public ControllerEndpointFilterInvocationContext(
     ControllerActionDescriptor actionDescriptor,
     ActionContext actionContext,
     ObjectMethodExecutor executor,
     IActionResultTypeMapper mapper,
     object controller,
     object?[]?arguments)
 {
     ActionDescriptor = actionDescriptor;
     ActionContext    = actionContext;
     Mapper           = mapper;
     Executor         = executor;
     Controller       = controller;
     Arguments        = arguments ?? Array.Empty <object?>();
 }
            public override async ValueTask <IActionResult> Execute(
                IActionResultTypeMapper mapper,
                ObjectMethodExecutor executor,
                object controller,
                object[] arguments)
            {
                // Async method returning Task<IActionResult>
                // Avoid extra allocations by calling Execute rather than ExecuteAsync and casting to Task<IActionResult>.
                var returnValue  = executor.Execute(controller, arguments);
                var actionResult = await(Task <IActionResult>) returnValue;

                EnsureActionResultNotNull(executor, actionResult);

                return(actionResult);
            }
 public ModelBindingActionInvokerFactory(
     ModelBindingActionInvokerCache modelBindingActionInvokerCache,
     IOptions <MvcOptions> optionsAccessor,
     ILoggerFactory loggerFactory,
     DiagnosticListener diagnosticListener,
     IActionResultTypeMapper mapper,
     IActionContextAccessor actionContextAccessor)
 {
     this.modelBindingActionInvokerCache = modelBindingActionInvokerCache;
     this.valueProviderFactories         = optionsAccessor.Value.ValueProviderFactories.ToArray();
     this.maxModelValidationErrors       = optionsAccessor.Value.MaxModelValidationErrors;
     this.logger                = loggerFactory.CreateLogger <ModelBindingActionInvoker>();
     this.diagnosticListener    = diagnosticListener;
     this.mapper                = mapper;
     this.actionContextAccessor = actionContextAccessor ?? ActionContextAccessorMock.Null;
 }
 public ControllerRequestDelegateFactory(
     ControllerActionInvokerCache controllerActionInvokerCache,
     IOptions <MvcOptions> optionsAccessor,
     ILoggerFactory loggerFactory,
     DiagnosticListener diagnosticListener,
     IActionResultTypeMapper mapper,
     IActionContextAccessor?actionContextAccessor)
 {
     _controllerActionInvokerCache = controllerActionInvokerCache;
     _valueProviderFactories       = optionsAccessor.Value.ValueProviderFactories.ToArray();
     _maxModelValidationErrors     = optionsAccessor.Value.MaxModelValidationErrors;
     _enableActionInvokers         = optionsAccessor.Value.EnableActionInvokers;
     _logger                = loggerFactory.CreateLogger <ControllerActionInvoker>();
     _diagnosticListener    = diagnosticListener;
     _mapper                = mapper;
     _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
 }
Exemplo n.º 25
0
        internal ControllerActionInvoker(
            ILogger logger,
            DiagnosticSource diagnosticSource,
            IActionResultTypeMapper mapper,
            ControllerContext controllerContext,
            MyControllerActionInvokerCacheEntry cacheEntry,
            IFilterMetadata[] filters)
            : base(diagnosticSource, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories)
        {
            if (cacheEntry == null)
            {
                throw new ArgumentNullException(nameof(cacheEntry));
            }

            _cacheEntry        = cacheEntry;
            _controllerContext = controllerContext;
        }
Exemplo n.º 26
0
        public ResourceInvoker(
            DiagnosticSource diagnosticSource,
            ILogger logger,
            IActionResultTypeMapper mapper,
            ActionContext actionContext,
            IFilterMetadata[] filters,
            IList <IValueProviderFactory> valueProviderFactories)
        {
            _diagnosticSource = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource));
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            _mapper           = mapper ?? throw new ArgumentNullException(nameof(mapper));
            _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);
        }
Exemplo n.º 27
0
 public TestControllerActionInvoker(
     IFilterMetadata[] filters,
     MockControllerFactory controllerFactory,
     ILogger logger,
     DiagnosticSource diagnosticSource,
     IActionResultTypeMapper mapper,
     ActionContext actionContext,
     IReadOnlyList <IValueProviderFactory> valueProviderFactories,
     int maxAllowedErrorsInModelState)
     : base(
         logger,
         diagnosticSource,
         mapper,
         CreateControllerContext(actionContext, valueProviderFactories, maxAllowedErrorsInModelState),
         CreateCacheEntry((ControllerActionDescriptor)actionContext.ActionDescriptor, controllerFactory),
         filters)
 {
     ControllerFactory = controllerFactory;
 }
 public MyPageActionInvokerProvider(
     IPageLoader loader,
     IPageFactoryProvider pageFactoryProvider,
     IPageModelFactoryProvider modelFactoryProvider,
     IRazorPageFactoryProvider razorPageFactoryProvider,
     IActionDescriptorCollectionProvider collectionProvider,
     IEnumerable <IFilterProvider> filterProviders,
     ParameterBinder parameterBinder,
     IModelMetadataProvider modelMetadataProvider,
     IModelBinderFactory modelBinderFactory,
     ITempDataDictionaryFactory tempDataFactory,
     IOptions <MvcOptions> mvcOptions,
     IOptions <HtmlHelperOptions> htmlHelperOptions,
     IPageHandlerMethodSelector selector,
     RazorProjectFileSystem razorFileSystem,
     DiagnosticSource diagnosticSource,
     ILoggerFactory loggerFactory,
     IActionResultTypeMapper mapper) : base(loader, pageFactoryProvider, modelFactoryProvider, razorPageFactoryProvider, collectionProvider, filterProviders, parameterBinder, modelMetadataProvider, modelBinderFactory, tempDataFactory, mvcOptions, htmlHelperOptions, selector, razorFileSystem, diagnosticSource, loggerFactory, mapper)
 {
 }
Exemplo n.º 29
0
 public PageActionInvokerProvider(
     IPageLoader loader,
     IPageFactoryProvider pageFactoryProvider,
     IPageModelFactoryProvider modelFactoryProvider,
     IRazorPageFactoryProvider razorPageFactoryProvider,
     IActionDescriptorCollectionProvider collectionProvider,
     IEnumerable <IFilterProvider> filterProviders,
     ParameterBinder parameterBinder,
     IModelMetadataProvider modelMetadataProvider,
     IModelBinderFactory modelBinderFactory,
     ITempDataDictionaryFactory tempDataFactory,
     IOptions <MvcOptions> mvcOptions,
     IOptions <HtmlHelperOptions> htmlHelperOptions,
     IPageHandlerMethodSelector selector,
     DiagnosticListener diagnosticListener,
     ILoggerFactory loggerFactory,
     IActionResultTypeMapper mapper,
     IActionContextAccessor actionContextAccessor)
 {
     _loader = loader;
     _pageFactoryProvider      = pageFactoryProvider;
     _modelFactoryProvider     = modelFactoryProvider;
     _modelBinderFactory       = modelBinderFactory;
     _razorPageFactoryProvider = razorPageFactoryProvider;
     _collectionProvider       = collectionProvider;
     _filterProviders          = filterProviders.ToArray();
     _valueProviderFactories   = mvcOptions.Value.ValueProviderFactories.ToArray();
     _parameterBinder          = parameterBinder;
     _modelMetadataProvider    = modelMetadataProvider;
     _tempDataFactory          = tempDataFactory;
     _mvcOptions            = mvcOptions.Value;
     _htmlHelperOptions     = htmlHelperOptions.Value;
     _selector              = selector;
     _diagnosticListener    = diagnosticListener;
     _logger                = loggerFactory.CreateLogger <PageActionInvoker>();
     _mapper                = mapper;
     _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null;
 }
Exemplo n.º 30
0
        public ModelBindingActionInvoker(
            ILogger logger,
            DiagnosticListener diagnosticListener,
            IActionContextAccessor actionContextAccessor,
            IActionResultTypeMapper mapper,
            ControllerContext controllerContext,
            dynamic cacheEntry,
            IFilterMetadata[] filters,
            bool fullExecution)
        {
            CommonValidator.CheckForNullReference(cacheEntry, nameof(cacheEntry));
            CommonValidator.CheckForNullReference(controllerContext, nameof(controllerContext));

            this.controllerContext = controllerContext;
            this.cacheEntry        = cacheEntry;

            filters = this.PrepareFilters(filters, fullExecution);

            var invokerType = WebFramework.Internals.ControllerActionInvoker;
            var constructor = invokerType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0];

            this.invoker = constructor.Invoke(new object[] { logger, diagnosticListener, actionContextAccessor, mapper, controllerContext, cacheEntry, filters });
        }