/// <summary> /// Adds a route to the <see cref="IRouteBuilder"/> configured for data fetching, with the specified name, template, default values, and /// data tokens. /// </summary> /// <param name="routeBuilder">The <see cref="IRouteBuilder"/> to add the route to.</param> /// <param name="name">The name of the route.</param> /// <param name="template">The URL pattern of the route.</param> /// <param name="defaults"> /// An object that contains default values for route parameters. The object's properties represent the names /// and values of the default values. /// </param> /// <param name="constraints"> /// An object that contains constraints for the route. The object's properties represent the names and values /// of the constraints. /// </param> /// <param name="dataTokens"> /// An object that contains data tokens for the route. The object's properties represent the names and values /// of the data tokens. /// </param> /// <param name="writePermission"> /// A permission object which specifies who can create or edit the content item via this route /// </param> /// <param name="divertOverride"> /// A function which checks whether to switch out the default inner router with one which diverts the user /// to an editor controller /// </param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IRouteBuilder MapDataRoute <T>( this IRouteBuilder routeBuilder, string name, string template, object defaults = null, object constraints = null, object dataTokens = null, ContentPermission writePermission = null, DiversionStrategy divertOverride = null) where T : class, new() { if (routeBuilder.DefaultHandler == null) { throw new InvalidOperationException("Default handler must be set"); } var inlineConstraintResolver = (IInlineConstraintResolver)routeBuilder .ServiceProvider .GetService(typeof(IInlineConstraintResolver)); // Interpose a DataFetchingRouter between the classic Route and the DefaultHandler, which // tries to fetch the data for the route var dataFetchingRouter = new DataFetchingRouter <T>(routeBuilder.DefaultHandler, false, writePermission, divertOverride); var dataRoute = new DataRoute( dataFetchingRouter, name, template, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints), new RouteValueDictionary(dataTokens), inlineConstraintResolver); routeBuilder.Routes.Add(dataRoute); // Record the data route on Lynicon's internal RouteCollection used for reverse url generation if (ContentMap.Instance.RouteCollection == null) { ContentMap.Instance.RouteCollection = new RouteCollection(); } ContentMap.Instance.RouteCollection.Add(dataRoute); Type registerType = typeof(T); if (registerType.IsGenericType() && registerType.GetGenericTypeDefinition() == typeof(List <>)) { registerType = registerType.GetGenericArguments()[0]; } ContentTypeHierarchy.RegisterType(registerType); return(routeBuilder); }
/// <summary> /// Adds a route to the <see cref="IRouteBuilder"/> configured for data fetching, with the specified name, template, default values, and /// data tokens. /// </summary> /// <param name="routeBuilder">The <see cref="IRouteBuilder"/> to add the route to.</param> /// <param name="name">The name of the route.</param> /// <param name="template">The URL pattern of the route.</param> /// <param name="defaults"> /// An object that contains default values for route parameters. The object's properties represent the names /// and values of the default values. /// </param> /// <param name="constraints"> /// An object that contains constraints for the route. The object's properties represent the names and values /// of the constraints. /// </param> /// <param name="dataTokens"> /// An object that contains data tokens for the route. The object's properties represent the names and values /// of the data tokens. /// </param> /// <param name="divertOverride"> /// A function which checks whether to switch out the default inner router with one which diverts the user /// to an editor controller /// </param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IRouteBuilder MapDataRoute <T>( this IRouteBuilder routeBuilder, string name, string template, object defaults, object constraints, object dataTokens, Func <IRouter, RouteContext, object, IRouter> divertOverride) where T : class, new() { if (routeBuilder.DefaultHandler == null) { throw new InvalidOperationException("Default handler must be set"); } var inlineConstraintResolver = (IInlineConstraintResolver)routeBuilder .ServiceProvider .GetService(typeof(IInlineConstraintResolver)); // Interpose a DataFetchingRouter between the classic Route and the DefaultHandler, which // tries to fetch the data for the route var dataFetchingRouter = new DataFetchingRouter <T>(routeBuilder.DefaultHandler, false, divertOverride); var dataRoute = new DataRoute( dataFetchingRouter, name, template, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints), new RouteValueDictionary(dataTokens), inlineConstraintResolver); routeBuilder.Routes.Add(dataRoute); // Record the data route on Lynicon's internal RouteCollection used for reverse url generation if (ContentMap.Instance.RouteCollection == null) { ContentMap.Instance.RouteCollection = new RouteCollection(); } ContentMap.Instance.RouteCollection.Add(dataRoute); ContentTypeHierarchy.RegisterType(typeof(T)); return(routeBuilder); }
public DataRoute( DataFetchingRouter target, string routeName, string routeTemplate, RouteValueDictionary defaults, IDictionary <string, object> constraints, RouteValueDictionary dataTokens, IInlineConstraintResolver inlineConstraintResolver) : base( (IRouter)target, routeName, routeTemplate, defaults, constraints, dataTokens, inlineConstraintResolver) { this.target = target; }