An open API service indexing awesome lists of open source software.

https://github.com/stringepsilon/theseus

URL Generator / IUrlHelper extension for asp.net
https://github.com/stringepsilon/theseus

actions aspnet-core dotnet mvc routing

Last synced: 3 months ago
JSON representation

URL Generator / IUrlHelper extension for asp.net

Awesome Lists containing this project

README

          

# Theseus

`IUrlHelper` extensions to point at a controller method to generate links.

Example:

```cs
// Regular IUrlHelper:
string aboutUrl = Url.Action("About", "Home");
string buyUrl = Url.Action("Buy", "Products", new { id = 17, color = "red" });

// Theseus:
string aboutUrl = Url.To(y => y.About());
string buyUrl = Url.To(y => y.Buy(17, "red"));
```

This library uses [EpsilonEvaluator](https://www.nuget.org/packages/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](https://github.com/ivaylokenov/AspNet.Mvc.TypedRouting) from Ivaylo Kenov.

## Performance

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(y => y.Index())` | 2085989 | Theseus with cache |
| `Url.To(y => y.Index())` | 591933 | Theseus without cache |
| `Url.Action(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(y => y.List(page))` | 442179 | Cache not applicable |
| `Url.Action(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(y => y.List(this.CurrentPage))` | 404453 | Without cache |
| `Url.Action(y => y.List(this.CurrentPage))` | 8729 | from Panelak.TypedRouting |
| `Url.Action("List", "Home", new { page = this.CurrentPage })` | 982898 | - |

## Thanks

- blockmath_2048 for the name suggestion.