コード例 #1
0
        public MvcEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            MvcEndpointInvokerFactory invokerFactory,
            ParameterPolicyFactory parameterPolicyFactory,
            RoutePatternTransformer routePatternTransformer)
        {
            _actions                 = actions;
            _invokerFactory          = invokerFactory;
            _parameterPolicyFactory  = parameterPolicyFactory;
            _routePatternTransformer = routePatternTransformer;

            ConventionalEndpointInfos           = new List <MvcEndpointInfo>();
            AttributeRoutingConventionResolvers = new List <Func <ActionDescriptor, DefaultEndpointConventionBuilder> >();

            // IMPORTANT: this needs to be the last thing we do in the constructor. Change notifications can happen immediately!
            //
            // It's possible for someone to override the collection provider without providing
            // change notifications. If that's the case we won't process changes.
            if (actions is ActionDescriptorCollectionProvider collectionProviderWithChangeToken)
            {
                ChangeToken.OnChange(
                    () => collectionProviderWithChangeToken.GetChangeToken(),
                    UpdateEndpoints);
            }
        }
コード例 #2
0
        public ActionEndpointFactory(
            RoutePatternTransformer routePatternTransformer,
            MvcEndpointInvokerFactory invokerFactory)
        {
            if (routePatternTransformer == null)
            {
                throw new ArgumentNullException(nameof(routePatternTransformer));
            }

            if (invokerFactory == null)
            {
                throw new ArgumentNullException(nameof(invokerFactory));
            }

            _routePatternTransformer = routePatternTransformer;
            _invokerFactory          = invokerFactory;
        }
コード例 #3
0
        private MvcEndpointDataSource CreateMvcEndpointDataSource(
            IActionDescriptorCollectionProvider actionDescriptorCollectionProvider = null,
            MvcEndpointInvokerFactory mvcEndpointInvokerFactory = null)
        {
            if (actionDescriptorCollectionProvider == null)
            {
                actionDescriptorCollectionProvider = new DefaultActionDescriptorCollectionProvider(
                    Array.Empty <IActionDescriptorProvider>(),
                    Array.Empty <IActionDescriptorChangeProvider>());
            }

            var services = new ServiceCollection();

            services.AddSingleton(actionDescriptorCollectionProvider);

            var routeOptionsSetup = new MvcCoreRouteOptionsSetup();

            services.Configure <RouteOptions>(routeOptionsSetup.Configure);
            services.AddRouting(options =>
            {
                options.ConstraintMap["upper-case"] = typeof(UpperCaseParameterTransform);
            });

            var serviceProvider = services.BuildServiceProvider();

            var dataSource = new MvcEndpointDataSource(
                actionDescriptorCollectionProvider,
                mvcEndpointInvokerFactory ?? new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty <IActionInvokerProvider>())),
                serviceProvider.GetRequiredService <ParameterPolicyFactory>(),
                serviceProvider.GetRequiredService <RoutePatternTransformer>());

            var defaultEndpointConventionBuilder = new DefaultEndpointConventionBuilder();

            dataSource.AttributeRoutingConventionResolvers.Add((actionDescriptor) =>
            {
                return(defaultEndpointConventionBuilder);
            });

            return(dataSource);
        }