如何在基本Web api控制器中提供可通过属性路由访问的方法

时间:2015-06-02 19:31:22

标签: inheritance asp.net-web-api routing

基类:

public class DataApiControllerBase<T> : ApiController
    {
        public List<ValidationResult> Validate(T input)
        {
            ...

        }
    }

派生类:

public class CustomerController: DataApiControllerBase<Customer>
    {
        [Route("api/customer/{id}")]
        public Customer Get([FromUri] Guid id)
       {

       }

    }

路由将解决什么问题,以便在每个派生的控制器端点上获得“验证”端点?这是解决这个问题的正确方法吗?

1 个答案:

答案 0 :(得分:0)

我会说你可以用方法覆盖来解决这个问题

基础课程

public class CustomerController: DataApiControllerBase<Customer>
{
    Route("api/customer/validate")]
    [HttpPost]
    public override List<ValidationResult> Validate(Customer input)
    {
        base.Validate(input);
    }

   Route("api/customer/{id}")]
   public Customer Get([FromUri] Guid id)
   {

   }
}   

派生类

element1 {
    height: calc(100% - 50px);
    -webkit-transition: .5s;
    -moz-transition: .5s;
    -ms-transition: .5s;
    -o-transition: .5s;
    transition: .5s;
}

element1:hover {
    height: calc(100% - 200px);
}