Beispiel #1
0
    public DefaultLinkGenerator(
        ParameterPolicyFactory parameterPolicyFactory,
        TemplateBinderFactory binderFactory,
        EndpointDataSource dataSource,
        IOptions <RouteOptions> routeOptions,
        ILogger <DefaultLinkGenerator> logger,
        IServiceProvider serviceProvider)
    {
        _binderFactory   = binderFactory;
        _logger          = logger;
        _serviceProvider = serviceProvider;

        // We cache TemplateBinder instances per-Endpoint for performance, but we want to wipe out
        // that cache is the endpoints change so that we don't allow unbounded memory growth.
        _cache = new DataSourceDependentCache <ConcurrentDictionary <RouteEndpoint, TemplateBinder> >(dataSource, (_) =>
        {
            // We don't eagerly fill this cache because there's no real reason to. Unlike URL matching, we don't
            // need to build a big data structure up front to be correct.
            return(new ConcurrentDictionary <RouteEndpoint, TemplateBinder>());
        });

        // Cached to avoid per-call allocation of a delegate on lookup.
        _createTemplateBinder = CreateTemplateBinder;

        _globalLinkOptions = new LinkOptions()
        {
            AppendTrailingSlash   = routeOptions.Value.AppendTrailingSlash,
            LowercaseQueryStrings = routeOptions.Value.LowercaseQueryStrings,
            LowercaseUrls         = routeOptions.Value.LowercaseUrls,
        };
    }
Beispiel #2
0
        public MvcEndpointInfo(
            string name,
            string pattern,
            RouteValueDictionary defaults,
            IDictionary <string, object> constraints,
            RouteValueDictionary dataTokens,
            ParameterPolicyFactory parameterPolicyFactory)
        {
            Name       = name;
            Pattern    = pattern ?? string.Empty;
            DataTokens = dataTokens;

            try
            {
                // Data we parse from the pattern will be used to fill in the rest of the constraints or
                // defaults. The parser will throw for invalid routes.
                ParsedPattern     = RoutePatternFactory.Parse(pattern, defaults, constraints);
                ParameterPolicies = BuildParameterPolicies(ParsedPattern.Parameters, parameterPolicyFactory);

                Defaults = defaults;
                // Merge defaults outside of RoutePattern because the defaults will already have values from pattern
                MergedDefaults = new RouteValueDictionary(ParsedPattern.Defaults);
            }
            catch (Exception exception)
            {
                throw new RouteCreationException(
                          string.Format(CultureInfo.CurrentCulture, "An error occurred while creating the route with name '{0}' and pattern '{1}'.", name, pattern), exception);
            }
        }
        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);
            }
        }
        public MvcEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            MvcEndpointInvokerFactory invokerFactory,
            ParameterPolicyFactory parameterPolicyFactory)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

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

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

            _actions                = actions;
            _invokerFactory         = invokerFactory;
            _parameterPolicyFactory = parameterPolicyFactory;

            ConventionalEndpointInfos = new List <MvcEndpointInfo>();

            // 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);
            }
        }
    public DefaultRoutePatternTransformer(ParameterPolicyFactory policyFactory)
    {
        if (policyFactory == null)
        {
            throw new ArgumentNullException(nameof(policyFactory));
        }

        _policyFactory = policyFactory;
    }
Beispiel #6
0
 public GlobalRouteValuesLinkGenerator(
     ParameterPolicyFactory parameterPolicyFactory,
     GlobalRouteValuesLinkGeneratorTemplateBinderFactory binderFactory,
     EndpointDataSource dataSource,
     IOptions <RouteOptions> routeOptions,
     ILogger <DefaultLinkGenerator> logger,
     IServiceProvider serviceProvider,
     IOptions <GlobalRouteValuesLinkGeneratorOptions> options)
     : base(parameterPolicyFactory, binderFactory, dataSource, routeOptions, logger, serviceProvider)
 {
     _globalRouteKeys = options.Value.GlobalRouteKeys ?? Array.Empty <string>();
 }
Beispiel #7
0
 public DfaBuilderWorker(
     List <DfaBuilderWorkerWorkItem> work,
     Comparer <DfaBuilderWorkerWorkItem> precedenceDigitComparer,
     bool includeLabel,
     ParameterPolicyFactory parameterPolicyFactory)
 {
     _work                    = work;
     _previousWork            = new List <DfaBuilderWorkerWorkItem>();
     _workCount               = work.Count;
     _precedenceDigitComparer = precedenceDigitComparer;
     _includeLabel            = includeLabel;
     _parameterPolicyFactory  = parameterPolicyFactory;
 }
Beispiel #8
0
        public DfaMatcherBuilder(
            ParameterPolicyFactory parameterPolicyFactory,
            EndpointSelector selector,
            IEnumerable <MatcherPolicy> policies)
        {
            _parameterPolicyFactory = parameterPolicyFactory;
            _selector = selector;
            _policies = policies.OrderBy(p => p.Order).ToArray();

            // Taking care to use _policies, which has been sorted.
            _nodeBuilders = _policies.OfType <INodeBuilderPolicy>().ToArray();
            _comparer     = new EndpointComparer(_policies.OfType <IEndpointComparerPolicy>().ToArray());
        }
    public DefaultTemplateBinderFactory(
        ParameterPolicyFactory policyFactory,
        ObjectPool <UriBuildingContext> pool)
    {
        if (policyFactory == null)
        {
            throw new ArgumentNullException(nameof(policyFactory));
        }

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

        _policyFactory = policyFactory;
        _pool          = pool;
    }
#pragma warning restore CS0618 // Type or member is obsolete

        public DefaultTemplateBinderFactory(
            ParameterPolicyFactory policyFactory,
#pragma warning disable CS0618 // Type or member is obsolete
            ObjectPool <UriBuildingContext> pool)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            if (policyFactory == null)
            {
                throw new ArgumentNullException(nameof(policyFactory));
            }

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

            _policyFactory = policyFactory;
            _pool          = pool;
        }
Beispiel #11
0
    public DefaultLinkParser(
        ParameterPolicyFactory parameterPolicyFactory,
        EndpointDataSource dataSource,
        ILogger <DefaultLinkParser> logger,
        IServiceProvider serviceProvider)
    {
        _parameterPolicyFactory = parameterPolicyFactory;
        _logger          = logger;
        _serviceProvider = serviceProvider;

        // We cache RoutePatternMatcher instances per-Endpoint for performance, but we want to wipe out
        // that cache is the endpoints change so that we don't allow unbounded memory growth.
        _matcherCache = new DataSourceDependentCache <ConcurrentDictionary <RouteEndpoint, MatcherState> >(dataSource, (_) =>
        {
            // We don't eagerly fill this cache because there's no real reason to. Unlike URL matching, we don't
            // need to build a big data structure up front to be correct.
            return(new ConcurrentDictionary <RouteEndpoint, MatcherState>());
        });

        // Cached to avoid per-call allocation of a delegate on lookup.
        _createMatcher = CreateRoutePatternMatcher;
    }
Beispiel #12
0
        private Dictionary<string, IList<IRouteConstraint>> BuildConstraints(ParameterPolicyFactory parameterPolicyFactory)
        {
            var constraints = new Dictionary<string, IList<IRouteConstraint>>(StringComparer.OrdinalIgnoreCase);

            foreach (var parameter in ParsedPattern.Parameters)
            {
                foreach (var parameterPolicy in parameter.ParameterPolicies)
                {
                    var createdPolicy = parameterPolicyFactory.Create(parameter, parameterPolicy);
                    if (createdPolicy is IRouteConstraint routeConstraint)
                    {
                        if (!constraints.TryGetValue(parameter.Name, out var paramConstraints))
                        {
                            paramConstraints = new List<IRouteConstraint>();
                            constraints.Add(parameter.Name, paramConstraints);
                        }

                        paramConstraints.Add(routeConstraint);
                    }
                }
            }

            return constraints;
        }
Beispiel #13
0
        internal static Dictionary <string, IList <IParameterPolicy> > BuildParameterPolicies(IReadOnlyList <RoutePatternParameterPart> parameters, ParameterPolicyFactory parameterPolicyFactory)
        {
            var policies = new Dictionary <string, IList <IParameterPolicy> >(StringComparer.OrdinalIgnoreCase);

            foreach (var parameter in parameters)
            {
                foreach (var parameterPolicy in parameter.ParameterPolicies)
                {
                    var createdPolicy = parameterPolicyFactory.Create(parameter, parameterPolicy);
                    if (!policies.TryGetValue(parameter.Name, out var policyList))
                    {
                        policyList = new List <IParameterPolicy>();
                        policies.Add(parameter.Name, policyList);
                    }

                    policyList.Add(createdPolicy);
                }
            }

            return(policies);
        }
 public BackCompatInlineConstraintResolver(IInlineConstraintResolver inner, ParameterPolicyFactory parameterPolicyFactory)
 {
     _inner = inner;
     _parameterPolicyFactory = parameterPolicyFactory;
 }