Goal: / v1 /whatever/path/here. I am pretty new to the ASP.Net Web API framework and at the begining it seemed to me that the task is easy. So I ended up with:
public override HttpControllerDescriptor SelectController(HttpRequestMessage request) {
var requestedVersion = ExtractOnlyVersionDigits(request);
var currentVersionControllers =
SelectControllersOfRequestedVersion(requestedVersion);
if (currentVersionControllers.Count() > 0) {
var appropriateController = currentVersionControllers.First(); // yeah, that is stupid, I know that
return new HttpControllerDescriptor(
_configuration,
appropriateController.Name,
appropriateController);
}
After 4 hours of coding I realized that it will not work with multiply controllers unsless I map them manually.
So my questiono is: 1) am I misusing this framework? 2) is there a simple way to reuse existing functionality? 3) if not, how can I impelment my version mapping WITHOUT declaring [RoutePrefix] or whatisit on each and very controller/action?
There is a good article by Scott Hanselman on versioning API's for ASP.NET
http://www.hanselman.com/blog/ASPNETCoreRESTfulWebAPIVersioningMadeEasy.aspx
Might be worth looking at that instead of trying to grow your own? :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.