Is ApiController deprecated in .NET Core

后端 未结 4 658
-上瘾入骨i
-上瘾入骨i 2021-01-31 01:04

Is it true that \"ApiController will get deprecated in .NET Core\"? Asking since I\'m planning to use it in new projects.

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 01:43

    The [ApiController] attribute actually got added back in ASP.NET Core version 2.1.

    Features coupled with the attribute are:

    • Validation errors automatically trigger an HTTP 400 response.
    • No more need to define [FromBody], [FromRoute], ... attributes explicitly

    Links to the docs:

    • https://docs.microsoft.com/en-us/aspnet/core/aspnetcore-2.1?view=aspnetcore-2.1#apicontroller-actionresult
    • https://docs.microsoft.com/en-us/aspnet/core/web-api/index?view=aspnetcore-2.1#annotate-class-with-apicontrollerattribute

    Update

    There is also the baseclass ControllerBase for controllers to inherit from which is suited for api-controllers because it ommits all view-related functionality.

    • https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase?view=aspnetcore-2.1

提交回复
热议问题