如何使用Razor页面设置垂直切片架构?

huangapple go评论117阅读模式
英文:

How to set a vertical slice architecture with Razor Pages?

问题

默认情况下,运行时会在Pages文件夹中查找 Razor 页面,所以您需要这样做:

Pages
  --Orders
  ----index.cshtml
  ----add.cshtml
  --Products
  ----index.cshtml
  ----add.cshtml

我该如何改成这样呢?

Orders
  --Pages
  ----index.cshtml
  ----add.cshtml
Products
  --Pages
  ----index.cshtml
  ----add.cshtml
英文:

By default the runtime looks for razor pages in the Pages folder, so you have to do this:

Pages
  --Orders
  ----index.cshtml
  ----add.cshtml
  --Products
  ----index.cshtml
  ----add.cshtml

How can I do this instead?

Orders
  --Pages
  ----index.cshtml
  ----add.cshtml
Products
  --Pages
  ----index.cshtml
  ----add.cshtml

答案1

得分: 1

这不是一个好主意。您需要指定一个文件夹作为Razor页面的根目录,以便路由正常工作,所以您仍然需要将您的产品和订单文件夹放在其中。如果在根文件夹中有一个名为"Pages"的文件夹,它将成为路由的一部分。所以,您必须覆盖框架生成的所有路由,除非您想要像这样的路由:

/orders/pages/add

第一个文件夹结构在垂直切片中运行良好。这是我做的方式。

英文:

This isn't a great idea. You need to specify one folder as the root for your Razor pages so that routing works so you still need to put your products and orders folder in that. And if you have a Pages folder in that root folder, it will become part of the route. So then you have to override all the routes that get generated by the framework unless you want to have routes like this:

/orders/pages/add

The first folder structure works fine with vertical slices. It's how I do it.

huangapple
  • 本文由 发表于 2023年4月10日 21:05:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定