//兼容ClownFish的多参数绑定
        private void CompatibilityClownFishWeb(
            ControllerActionDescriptor actionDescriptor,
            ControllerActionInvokerCacheEntry controllerActionInvokerCacheEntry)
        {
            // 合并参数绑定委托
            var controllerBinderDelegate = MergeControllerBinderDelegate(Bind,
                                                                         controllerActionInvokerCacheEntry.ControllerBinderDelegate);

//            var objectMethodExecutor = controllerActionInvokerCacheEntry?.GetType()
//                .GetProperty("ObjectMethodExecutor")?.GetValue(controllerActionInvokerCacheEntry);
//            var actionMethodExecutor = controllerActionInvokerCacheEntry?.GetType()
//                .GetProperty("ActionMethodExecutor")?.GetValue(controllerActionInvokerCacheEntry);

            // 替换ControllerActionInvokerCacheEntry中的参数绑定委托
            controllerActionInvokerCacheEntry = ReplaceCacheEntry(controllerActionInvokerCacheEntry, controllerBinderDelegate);

//            object obj=Activator.CreateInstance(typeof(ControllerActionInvokerCacheEntry), BindingFlags.Instance | BindingFlags.NonPublic,
//                null, new object[]
//                {
//                    controllerActionInvokerCacheEntry.CachedFilters,
//                    controllerActionInvokerCacheEntry.ControllerFactory,
//                    controllerActionInvokerCacheEntry.ControllerReleaser,
//                    controllerBinderDelegate,
//                    objectMethodExecutor,
//                    actionMethodExecutor
//                }, null);

            // 改写缓存,新的缓存中使用新的参数绑定委托,支持多参数绑定
            var cache = GetCache();

            cache[actionDescriptor] = controllerActionInvokerCacheEntry;
        }
Exemplo n.º 2
0
    public (ControllerActionInvokerCacheEntry cacheEntry, IFilterMetadata[] filters) GetCachedResult(ControllerContext controllerContext)
    {
        var actionDescriptor = controllerContext.ActionDescriptor;

        IFilterMetadata[] filters;

        var cacheEntry = actionDescriptor.CacheEntry;

        // We don't care about thread safety here
        if (cacheEntry is null)
        {
            var filterFactoryResult = FilterFactory.GetAllFilters(_filterProviders, controllerContext);
            filters = filterFactoryResult.Filters;

            var parameterDefaultValues = ParameterDefaultValues
                                         .GetParameterDefaultValues(actionDescriptor.MethodInfo);

            var objectMethodExecutor = ObjectMethodExecutor.Create(
                actionDescriptor.MethodInfo,
                actionDescriptor.ControllerTypeInfo,
                parameterDefaultValues);

            var controllerFactory     = _controllerFactoryProvider.CreateControllerFactory(actionDescriptor);
            var controllerReleaser    = _controllerFactoryProvider.CreateAsyncControllerReleaser(actionDescriptor);
            var propertyBinderFactory = ControllerBinderDelegateProvider.CreateBinderDelegate(
                _parameterBinder,
                _modelBinderFactory,
                _modelMetadataProvider,
                actionDescriptor,
                _mvcOptions);

            var actionMethodExecutor = ActionMethodExecutor.GetExecutor(objectMethodExecutor);
            var filterExecutor       = actionDescriptor.FilterDelegate is not null
                ? ActionMethodExecutor.GetFilterExecutor(actionDescriptor)
                : null;

            cacheEntry = new ControllerActionInvokerCacheEntry(
                filterFactoryResult.CacheableFilters,
                controllerFactory,
                controllerReleaser,
                propertyBinderFactory,
                objectMethodExecutor,
                filterExecutor ?? actionMethodExecutor,
                actionMethodExecutor);

            actionDescriptor.CacheEntry = cacheEntry;
        }
        else
        {
            // Filter instances from statically defined filter descriptors + from filter providers
            filters = FilterFactory.CreateUncachedFilters(_filterProviders, controllerContext, cacheEntry.CachedFilters);
        }

        return(cacheEntry, filters);
    }
Exemplo n.º 3
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;
        }
    internal ControllerActionInvoker(
        ILogger logger,
        DiagnosticListener diagnosticListener,
        IActionContextAccessor actionContextAccessor,
        IActionResultTypeMapper mapper,
        ControllerContext controllerContext,
        ControllerActionInvokerCacheEntry cacheEntry,
        IFilterMetadata[] filters)
        : base(diagnosticListener, logger, actionContextAccessor, mapper, controllerContext, filters, controllerContext.ValueProviderFactories)
    {
        if (cacheEntry == null)
        {
            throw new ArgumentNullException(nameof(cacheEntry));
        }

        _cacheEntry        = cacheEntry;
        _controllerContext = controllerContext;
    }
        /// <summary>
        ///
        /// </summary>
        /// <param name="self"></param>
        /// <returns></returns>
        public static ObjectMethodExecutor GetObjectMethodExecutor(this ControllerActionInvokerCacheEntry self)
        {
            var value = _objectMethodExecutorPropertyInfo.GetValue(self);

            return(new ObjectMethodExecutor(value));
        }
 /// <summary>
 /// 替换cacheEntry;
 /// </summary>
 /// <param name="cacheEntry"></param>
 /// <param name="binderDelegate"></param>
 /// <returns></returns>
 private static ControllerActionInvokerCacheEntry ReplaceCacheEntry(ControllerActionInvokerCacheEntry cacheEntry,
                                                                    ControllerBinderDelegate binderDelegate)
 {
     return(s_getCacheEntryDelegate.Value(cacheEntry, binderDelegate));
 }