Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

Commented Unassigned: Support MethodInfo-based route generation [1083]

$
0
0
Moq has a nice way to specify a method you want to call, using syntax like this:
mock.Setup(o => o.Do("foo", "bar).Returns(true));
The Setup portion here might work well for generating Web API routes.
For example:
public void MyController : ApiController
{
[HttpGet("...")]
public IHttpActionResult GetItem(int container, string name) { /* ... */ }

[HttpGet("...")]
public IHttpActionResult GetItems()
{
string link = Url.Route(() => this.Get(1, "a");
// ...
}
}

Using a lambda to call a method is a convenient way to represent a route.

Body params would be a little tricky (likely have to be default(T) and ignored). And disambiguating between multiple route prefixes might require something like this:
Url.Content("~/a/b", () => this.Get("a", 1));

But especially for mainline cases, the syntax is quite nice.
Comments: This is a feature request.

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>