Exemplo n.º 1
0
            private static ControllerActionInvokerCacheEntry CreateCacheEntry(
                ControllerActionDescriptor actionDescriptor,
                MockControllerFactory controllerFactory)
            {
                var objectMethodExecutor = CreateExecutor(actionDescriptor);

                return(new ControllerActionInvokerCacheEntry(
                           new FilterItem[0],
                           controllerFactory.CreateController,
                           controllerFactory.ReleaseController,
                           null,
                           objectMethodExecutor,
                           ActionMethodExecutor.GetExecutor(objectMethodExecutor)));
            }
Exemplo n.º 2
0
 internal ControllerActionInvokerCacheEntry(
     FilterItem[] cachedFilters,
     Func <ControllerContext, object> controllerFactory,
     Action <ControllerContext, object> controllerReleaser,
     ControllerBinderDelegate controllerBinderDelegate,
     ObjectMethodExecutor objectMethodExecutor,
     ActionMethodExecutor actionMethodExecutor)
 {
     ControllerFactory        = controllerFactory;
     ControllerReleaser       = controllerReleaser;
     ControllerBinderDelegate = controllerBinderDelegate;
     CachedFilters            = cachedFilters;
     ObjectMethodExecutor     = objectMethodExecutor;
     ActionMethodExecutor     = actionMethodExecutor;
 }
        public (ControllerActionInvokerCacheEntry cacheEntry, IFilterMetadata[] filters) GetCachedResult(ControllerContext controllerContext)
        {
            var cache            = CurrentCache;
            var actionDescriptor = controllerContext.ActionDescriptor;

            IFilterMetadata[] filters;
            if (!cache.Entries.TryGetValue(actionDescriptor, out var cacheEntry))
            {
                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.CreateControllerReleaser(actionDescriptor);
                var propertyBinderFactory = ControllerBinderDelegateProvider.CreateBinderDelegate(
                    _parameterBinder,
                    _modelBinderFactory,
                    _modelMetadataProvider,
                    actionDescriptor,
                    _mvcOptions);

                var actionMethodExecutor = ActionMethodExecutor.GetExecutor(objectMethodExecutor);

                cacheEntry = new ControllerActionInvokerCacheEntry(
                    filterFactoryResult.CacheableFilters,
                    controllerFactory,
                    controllerReleaser,
                    propertyBinderFactory,
                    objectMethodExecutor,
                    actionMethodExecutor);
                cacheEntry = cache.Entries.GetOrAdd(actionDescriptor, cacheEntry);
            }
            else
            {
                // Filter instances from statically defined filter descriptors + from filter providers
                filters = FilterFactory.CreateUncachedFilters(_filterProviders, controllerContext, cacheEntry.CachedFilters);
            }

            return(cacheEntry, filters);
        }