ASP MVC 5 Attribute routing VS. Convention-based routing

后端 未结 4 1145
不知归路
不知归路 2021-02-02 13:30

ASP MVC 5 has a new Routing called attribute routing. The way I see it, the routes are now scattered on every controller unlike with the convention-based that there is single lo

4条回答
  •  礼貌的吻别
    2021-02-02 14:00

    To address your first question, scattering the routes has a number of advantages:

    1. It puts the route information adjacent to the controller action that implements that route. This helps in debugging and troubleshooting, as well as providing an ability to quickly search for route information in your solution.

    2. It reduces risk in the process of making changes to routes. In RouteConfig.cs or WebApiConfig.cs (in the case of Web API solutions), the possibility exists to inadvertently change the wrong route or otherwise adversely affect other parts of your application.

    3. You may also want to include acceptable HTTP methods, permitted user types and registration priorities, which if included with the attribute-based routes, put all of that information together in one place.

    This post provided inspiration and reinforcement for me on the above, and goes into more detail: http://kevinmontrose.com/2011/07/25/why-i-love-attribute-based-routing/

提交回复
热议问题