asp.net mvc - How can I enforce url conventions for my web application? -


as architect, application i'm building has rest-compliant url scheme represents domain accurately, want way enforce convention has following properties:

  • pit of success (easier dev right wrong)
  • follows class convention, unless doesn't, in case it's overridable
  • routes stored in centralized location in codebase
  • takes advantage of type system (strongly-typed controller actions instead of inspecting request variables parameters inside action)
  • versionable

in experience, class naming , action naming conventions fall apart (the domain model doesn't follow object model, or developers find difficult debug routes), , application reverts attribute routing. attribute routing has number of drawbacks, , can become wild west environment several url styles grow together.

what's out there solve seemingly common problem?

well, you're looking third option doesn't exist. traditional routing , attribute routing pretty cover scenarios. use weighing pros , cons of each.

traditional routing conventions-based approach, if you're looking devs don't have think about, that's it. default /controller/action format, can create other routes specific scenarios want else. routes centralized in routeconfig.cs, , routing-related helpers in htmlhelper , urlhelper can called strongly-typed: html.actionlink<foocontroller>(m => m.index(), "foo").

about item not ticked off list "versionable", i'm not sure how expect work anyways? mind instantly goes web api , prefixing routes v1, v2, etc. if that's you're talking about, can traditional routing.

if want more flexible, that's attribute routing comes in, , in truth, can mix , match traditional routing , attribute routing best of both worlds. attribute routing lot less formalized, that's kind of point.

ultimately, comes down standards within organization though. there no programming language, framework, or system of routing ever lock in 1 way of doing things time. if want standardization, have enforce standardization. things code reviews, qa, etc. come in. shouldn't expect framework solve institutional problems you, because never will.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -