/// <summary> /// Initialise the core dbcontext, the collator, the repository and the editor redirect for a content type /// </summary> /// <param name="t">content type</param> /// <param name="coll">the collator</param> /// <param name="repo">the repository</param> /// <param name="redir">the editor redirect</param> public void SetupType(Type t, ICollator coll, IRepository repo, DiversionStrategy divert) { if ((coll ?? this.Registered(null)).ContainerType(t) == t) // type t is its own container, so it may be extended { System.Extender.RegisterForExtension(t); } if (!typeof(IContentContainer).IsAssignableFrom(t)) { ContentTypeHierarchy.RegisterType(t); } if (coll != null) { coll.System = this.System; this.Register(t, coll); } if (repo != null) { System.Repository.Register(t, repo); } if (divert != null) { DataDiverter.Instance.Register(t, divert); } }
/// <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); }
public static void AddTestDataRoute <T>(this RouteCollection routes, string name, string template, object defaults, ContentPermission writePermission = null, DiversionStrategy divertOverride = null) where T : class, new() { IOptions <RouteOptions> routeOpts = Options.Create <RouteOptions>(new RouteOptions()); var constraintResolver = new DefaultInlineConstraintResolver(routeOpts); var dataFetchingRouter = new DataFetchingRouter <T>(new MockRouter(), false, writePermission, divertOverride); var dataRoute = new DataRoute( dataFetchingRouter, name, template, new RouteValueDictionary(defaults), new RouteValueDictionary(null), new RouteValueDictionary(null), constraintResolver); routes.Add(dataRoute); }
/// <summary> /// Initialise the type system, the collator, the repository and the editor redirect for a content type /// </summary> /// <typeparam name="T">content type</typeparam> /// <param name="coll">the collator</param> /// <param name="repo">the repository</param> /// <param name="redir">the editor redirect</param> public static void SetupType <T>(this ITypeSystemRegistrar regr, ICollator coll, IRepository repo, DiversionStrategy redir) { regr.SetupType(typeof(T), coll, repo, redir); }