ploeh / Hyprlinkr

A URI building helper library for ASP.NET Web API
MIT License
197 stars 34 forks source link

Support for Async controller methods for WebAPI #42

Closed barbosatek closed 7 years ago

barbosatek commented 7 years ago

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 commented 7 years ago

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

barbosatek commented 7 years ago

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 commented 7 years ago

Hyprlinkr only partially works with attribute-based routes: https://github.com/ploeh/Hyprlinkr/issues/30

ploeh commented 7 years ago

Closing due to inactivity.