2017-10-28 108 views

回答

0

根據您的要求,我跟着Microsoft/aspnet-api-versioning檢查azure移動應用項目的版本。你可以參考下面的細節來達到你的目的。

安裝Microsoft.AspNet.WebApi.Versioning包。

Startup.MobileApp.cs啓用API版本如下:

public static void ConfigureMobileApp(IAppBuilder app) 
{ 
    HttpConfiguration config = new HttpConfiguration(); 

    var constraintResolver = new DefaultInlineConstraintResolver() 
    { 
     ConstraintMap = 
      { 
       ["apiVersion"] = typeof(ApiVersionRouteConstraint) 
      } 
    }; 
    config.AddApiVersioning(); 
    config.MapHttpAttributeRoutes(constraintResolver); 

    //your mobile configuration 

    app.UseWebApi(config); 
} 

爲了您TableController,你可以如下定義它:

表/ 1.0 /的TodoItem

[ApiVersion("1.0")] 
[RoutePrefix("tables/v{version:apiVersion}/todoitem")] 
public class TodoItemController : TableController<ToDoItem> 
{ 
    private MobileServiceContext context; 
    protected override void Initialize(HttpControllerContext controllerContext) 
    { 
     base.Initialize(controllerContext); 
     context = new MobileServiceContext(); 
     DomainManager = new EntityDomainManager<ToDoItem>(context, Request); 
    } 

    [Route] 
    // GET tables/v{version}/todoitem 
    public IQueryable<ToDoItem> GetAllTodoItems() 
    { 
     return Query(); 
    } 
} 

tables/v2.0/todoitem

[ApiVersion("2.0")] 
[ControllerName("TodoItem")] 
[RoutePrefix("tables/v{version:apiVersion}/todoitem")] 
public class TodoItemV2Controller : TableController<ToDoItem> 
{ 
    private MobileServiceContext context; 
    protected override void Initialize(HttpControllerContext controllerContext) 
    { 
     base.Initialize(controllerContext); 
     context = new MobileServiceContext(); 
     DomainManager = new EntityDomainManager<ToDoItem>(context, Request); 
    } 

    [Route] 
    // GET tables/v{version}/todoitem 
    public IQueryable<ToDoItem> GetAllTodoItems() 
    { 
     return Query(); 
    } 
} 

有關更多詳細信息,請參閱ASP.NET API Versioning

+0

感謝您的回覆。無法使用此方法進行路由,因爲我正在使用Azure移動應用程序(AMS)項目。 –

相關問題