我不完全确定我们要做的是与众不同但我无法弄清楚如何实际做到这一点。
我们想要做的是在同一端口上运行多个可独立部署的WebApi项目。实际上我们想要下面这样的东西:
http://api.company.com/api/Sales/v1/[Customer]
http://api.company.com/api/Sales/v3/[Products]
http://api.company.com/api/Sales/v5/[Orders]
http://api.company.com/api/Sales/v2/[Pricing]
http://api.company.com/api/Sales/v1/[Rewards]
将人员,产品,订单,定价和奖励作为自己独立的WebAPI项目。
但是我们也希望能够在每个项目中定义http://api.company.com/api/Sales之后的路线,这样每个项目都可以定义自己的版本,可以由不同的团队控制。
现在我正在设置我们的第一个新的WebApi项目,在我的控制器中我做了以下操作。
[RoutePrefix("v1/Customer")]
public class CustomerController : ApiController
{
[Route("{argCustomerNumber}")]
[HttpGet]
[ResponseType(typeof(Customer))]
public HttpResponseMessage LoadCustomer(string argCustomerNumber)
{
//Loades customer into a HttpResponseMessage
}
[Route("{argCustomerNumber}")]
[HttpPut]
public HttpResponseMessage ReplaceCustomerData(string argCustomerNumber, [FromBody] CustomerData argCustomerData)
{
//Updates customer in Database
}
[Route("{argCustomerNumber}/LicenseAgreements")]
[HttpGet]
public HttpResponseMessage LoadLicenseAgreement(string argCustomerNumber)
{
//Loads if they have signed the agreement
}
//.... You get the idea
}
当我们将其部署到我们的IIS服务器时,我们将其设置在虚拟文件夹结构下。
通过这种方式设置它只会在我预期http://api.company.com/api/Sales/v1/Customer/v1/Customer/1
时响应http://api.company.com/api/Sales/v1/Customer/1时才会响应我想做的甚至可能吗?