ASP.NET Web API-多个API/命名空间 [英] Asp.NET Web Api - multiple apis/namespaces

查看:153
本文介绍了ASP.NET Web API-多个API/命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MVC4网络应用程序中,我需要支持多个API.我环顾四周,显然是在Web API中,不支持在不同名称空间中使用相同名称的Controller.

In my MVC4 web app, I need to support multiple APIs. I looked around and apparently in Web API, Controllers with same name in different name spaces is not supported.

我有什么选择?

例如:我希望能够向我的API使用者提供类似的链接,

Ex: I want to be able to provide to my API consumers links like,

http://domainurl/api/api1/Students...
http://domainurl/api/api2/Students...

api1中的学生资源可以与api2中的学生资源完全不同. 在这种情况下,最好的方法是什么?我不想将其设为单个api并通过url参数进行处理.

A Student Resource in api1 can be totally different from the one in api2. In such cases what is the best approach? I do not want to make it a single api and handle it through url parameters.

推荐答案

也许最好将两个不同的API分成两个不同的项目,并让他们担心自己的Apis.

Maybe it might be better to seperate the 2 different APIs in to two different projects and have them worry about their own Apis.

  • MyApi.V1.csproj
  • MyApi.V2.csproj

然后让IIS使用虚拟应用程序指向单独的版本

Then have IIS point to the seperate versions using a virtual application

  • http://myapi.com/v1/values
  • http://myapi.com/v2/values

我认为这比将它们粉碎到相同的项目文件中更容易管理.另外,如果您决定使用任何解析器,这将有助于每个项目进行反思.

I think this is more manageable than smashing them into the same project file. Plus this will help each project out with reflection if you decide to use any resolvers.

这篇关于ASP.NET Web API-多个API/命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆