Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Async controller methods for WebAPI #42

Closed
barbosatek opened this issue Dec 15, 2016 · 4 comments
Closed

Support for Async controller methods for WebAPI #42

barbosatek opened this issue Dec 15, 2016 · 4 comments
Labels

Comments

@barbosatek
Copy link

While the following workaround works for MVC, AsyncController is not available on WebAPI, is there a workaround for it?

Uri actual = linker.GetUriAsync((AsyncController c) => c.Get(id)).Result;

@ploeh
Copy link
Owner

ploeh commented Dec 15, 2016

The AsyncController in that example code snippet is Ploeh.Hyprlinkr.UnitTest.Controllers.AsyncController, an example class that demonstrates how you'd get a Uri from a Controller with an async action method: https://github.com/ploeh/Hyprlinkr/blob/master/Hyprlinkr.UnitTest/RouteLinkerTests.cs#L350-L363

Hyprlinkr only works with ASP.NET Web API.

HTH

@ploeh ploeh added the question label Dec 15, 2016
@barbosatek
Copy link
Author

barbosatek commented Dec 15, 2016

Would this work if I only have attribute based routes? I'm not even defining the "DefaultApi" route.

var uri = await linker.GetUriAsync((DependentsV1Controller x) => x.Get(model.CompanyId, model.EmployeeId));

Seems to just hang infinetly while awaiting, deadlock?

UPDATE:
It seems it's a deadlock. If I use:
var uri = Task.Run(() => { return linker.GetUri((DependentsV1Controller x) => x.Get(model.CompanyId, model.EmployeeId)); }).Result;

instead of

Task.Factory.StartNew<Uri>((Func<Uri>) (() => this.GetUri(methodCallExp)));

I get the actual exception.

Additional information: A route named 'DefaultApi' could not be found in the route collection.

@ploeh
Copy link
Owner

ploeh commented Dec 15, 2016

Hyprlinkr only partially works with attribute-based routes: #30

@ploeh
Copy link
Owner

ploeh commented Feb 18, 2017

Closing due to inactivity.

@ploeh ploeh closed this as completed Feb 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants