예제 #1
0
        public DefaultLinkGenerator(
            ParameterPolicyFactory parameterPolicyFactory,
            TemplateBinderFactory binderFactory,
            EndpointDataSource dataSource,
            IOptions <RouteOptions> routeOptions,
            ILogger <DefaultLinkGenerator> logger,
            IServiceProvider serviceProvider)
        {
            _parameterPolicyFactory = parameterPolicyFactory;
            _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,
            };
        }
예제 #2
0
 public DefaultLinkGenerator(
     ParameterPolicyFactory parameterPolicyFactory,
     ObjectPool <UriBuildingContext> uriBuildingContextPool,
     IOptions <RouteOptions> routeOptions,
     ILogger <DefaultLinkGenerator> logger,
     IServiceProvider serviceProvider)
 {
     _parameterPolicyFactory = parameterPolicyFactory;
     _uriBuildingContextPool = uriBuildingContextPool;
     _options         = routeOptions.Value;
     _logger          = logger;
     _serviceProvider = serviceProvider;
 }
예제 #3
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;
        }
예제 #4
0
        public OrderLinkGenerator(
            ParameterPolicyFactory parameterPolicyFactory,
            TemplateBinderFactory binderFactory,
            EndpointDataSource dataSource,
            IOptions <RouteOptions> routeOptions,
            IServiceProvider serviceProvider)
        {
            if (typeInner.FullName != typeName)
            {
                throw new NotImplementedException();
            }
            var logger   = serviceProvider.GetService(typeof(ILogger <>).MakeGenericType(typeInner));
            var autoFlag = BindingFlags.NonPublic | BindingFlags.Instance;

            var args = new object[]
            {
                parameterPolicyFactory,
                binderFactory,
                dataSource,
                routeOptions,
                logger,
                serviceProvider
            };

            var ctorInfo = typeInner.GetConstructors()[0];
            var newExp   = Expression.New(ctorInfo, args.Select(o => Expression.Constant(o)));
            var ctor     = Expression.Lambda <Func <LinkGenerator> >(newExp).Compile();

            inner = ctor();

            _binderFactory        = binderFactory;
            _createTemplateBinder = CreateTemplateBinder;
            var fieldInfo = typeInner.GetField(nameof(_createTemplateBinder), autoFlag);

            fieldInfo.SetValue(inner, _createTemplateBinder);

            _requiredKeys = typeof(TemplateBinder).GetField(nameof(_requiredKeys), autoFlag);
        }