public TreeRouteBuilder( ILoggerFactory loggerFactory, RoutePatternBinderFactory binderFactory, IInlineConstraintResolver constraintResolver) { if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } if (binderFactory == null) { throw new ArgumentNullException(nameof(binderFactory)); } if (constraintResolver == null) { throw new ArgumentNullException(nameof(constraintResolver)); } _binderFactory = binderFactory; _constraintResolver = constraintResolver; _logger = loggerFactory.CreateLogger <TreeRouter>(); _constraintLogger = loggerFactory.CreateLogger(typeof(RouteConstraintMatcher).FullName); }
public TemplateBinderTests() { BinderFactory = new RoutePatternBinderFactory(new UrlTestEncoder(), new DefaultObjectPoolProvider()); }
public TreeRouter( UrlMatchingTree[] trees, IEnumerable <OutboundRouteEntry> linkGenerationEntries, RoutePatternBinderFactory binderFactory, ILogger routeLogger, ILogger constraintLogger, int version) { if (trees == null) { throw new ArgumentNullException(nameof(trees)); } if (linkGenerationEntries == null) { throw new ArgumentNullException(nameof(linkGenerationEntries)); } if (binderFactory == null) { throw new ArgumentNullException(nameof(binderFactory)); } if (routeLogger == null) { throw new ArgumentNullException(nameof(routeLogger)); } if (constraintLogger == null) { throw new ArgumentNullException(nameof(constraintLogger)); } _trees = trees; _logger = routeLogger; _constraintLogger = constraintLogger; _namedEntries = new Dictionary <string, OutboundMatch>(StringComparer.OrdinalIgnoreCase); var outboundMatches = new List <OutboundMatch>(); foreach (var entry in linkGenerationEntries) { var binder = new TemplateBinder(binderFactory.Create(entry.RouteTemplate.ToRoutePattern(), entry.Defaults)); var outboundMatch = new OutboundMatch() { Entry = entry, TemplateBinder = binder }; outboundMatches.Add(outboundMatch); // Skip unnamed entries if (entry.RouteName == null) { continue; } // We only need to keep one OutboundMatch per route template // so in case two entries have the same name and the same template we only keep // the first entry. OutboundMatch namedMatch; if (_namedEntries.TryGetValue(entry.RouteName, out namedMatch) && !string.Equals( namedMatch.Entry.RouteTemplate.TemplateText, entry.RouteTemplate.TemplateText, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException( Resources.FormatAttributeRoute_DifferentLinkGenerationEntries_SameName(entry.RouteName), nameof(linkGenerationEntries)); } else if (namedMatch == null) { _namedEntries.Add(entry.RouteName, outboundMatch); } } // The decision tree will take care of ordering for these entries. _linkGenerationTree = new LinkGenerationDecisionTree(outboundMatches.ToArray()); Version = version; }