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
- Host: GitHub
- URL: https://github.com/stringepsilon/theseus
- Owner: StringEpsilon
- License: mpl-2.0
- Created: 2023-10-24T17:04:00.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-19T16:49:53.000Z (9 months ago)
- Last Synced: 2025-10-10T22:11:34.577Z (4 months ago)
- Topics: actions, aspnet-core, dotnet, mvc, routing
- Language: C#
- Homepage:
- Size: 30.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE.md
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.