Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The basic requirements of content management are to persist arbitrary structured data associated with a group of urls, 
allow that data to be edited through a UI, and to provide that data to be inserted into a page template.
This is done in a clean light-touch way in Lynicon by simply extending the Route class.  Lynicon provides a generic 
DataRoute class, which when used, manages retrieval of an arbitrarily (within certain specifications) typed data item and 
provision of it to the controller's action method via model binding.

image 

The most basic scenario of content routing would then be implemented like this:

  • Create a content type TestContent
Code Block
languagec#
public class TestContent : BaseContent
{

...

	public string Title { get; set; }
}
  • Register a DataRoute<TestContent> in RouteConfig.cs, sending requests to TestController action Index
Code Block
languagec#
...
routes.AddDataRoute<TestContent>("test", "test/{_0}", new { controller = "test", action = "index" });
...
  • Add a parameter on the Index method of type TestContent named (by convention) 'data'.
Code Block
languagec#
public ActionResult Index(TestContent data)
{

...

	return View(data);
}

Lynicon comes with 2 standard kinds of persistence.  The default, as above, serializes content types before storing them in a dedicated database table along with metadata.  This is Content persistence.  Another kind exists called Basic persistence which simply stores each field as a database field, this is described elsewhere.

...

DataRoute<T> uses convention to map url variables (e.g. {action}) to an address which specifies a particular data item to retrieve.  The address is a tuple composed of all url variable values where the url variable is underscore followed by a number, starting zero.  E.g.

  shops/{_0}/{_1}

could be a url pattern for shops where the town they are in matches {_0} and the name of the shop matches {_1} e.g.

  shops/brighton/berts-fish-and-chips

If there are no url variables e.g. for the home page where the url is the empty string, there is only one (or zero) data item for the route.

...