IUrlHelper
extensions to point at a controller method to generate links.
Example:
// Regular IUrlHelper:
string aboutUrl = Url.Action("About", "Home");
string buyUrl = Url.Action("Buy", "Products", new { id = 17, color = "red" });
// Theseus:
string aboutUrl = Url.To<HomeController>(y => y.About());
string buyUrl = Url.To<ProductsController>(y => y.Buy(17, "red"));
This library uses EpsilonEvaluator to evaluate the route parameters from the method arguments. Most expressions should be evaluated without compilation and compiled expressions are not cached.
Inspired by AspNet.Mvc.TypedRouting from Ivaylo Kenov.
Theseus is of course slower than generating the links the regular way.
If you want expression based routing with really good performance, take a look at https://github.com/mariusz96/uri-generation, it beats Theseus consistently, sometimes by as much as 200%. But the API is very different.
Generate links to method without parameters:
Method | Links per second | Note |
---|---|---|
Url.To<HomeController>(y => y.Index()) |
2085989 | Theseus with cache |
Url.To<HomeController>(y => y.Index()) |
591933 | Theseus without cache |
Url.Action<HomeController>(y => y.Index()) |
535429 | from Panelak.TypedRouting |
Url.Action("Index", "Home") |
1105261 | - |
Generate links to method with scoped variable parameter:
Method | Links per second | Note |
---|---|---|
Url.To<HomeController>(y => y.List(page)) |
442179 | Cache not applicable |
Url.Action<HomeController>(y => y.List(page)) |
401513 | from Panelak.TypedRouting |
Url.Action("List", "Home", new { page }) |
976240 | - |
Generate links to method with property parameter:
Method | Links per second | Note |
---|---|---|
Url.To<HomeController>(y => y.List(this.CurrentPage)) |
404453 | Without cache |
Url.Action<HomeController>(y => y.List(this.CurrentPage)) |
8729 | from Panelak.TypedRouting |
Url.Action("List", "Home", new { page = this.CurrentPage }) |
982898 | - |
- blockmath_2048 for the name suggestion.