OpenRasta URI 实现问题

发布于 2024-12-20 14:20:13 字数 224 浏览 2 评论 0原文

我正在 OpenRasta 中为配置文件中的资源实现 URI。该特定资源是多个资源的子实体。 父母和孩子是一对多的关系。所有父实体都通过代码中的枚举类型拥有 int 值。

现在我想像这样实现我的 URI:

{ParentEntityName}/{ParentId}/{ChildName}/{ChildId}

我该如何实现这个?我是否需要为每个父实体进行单独的配置,还是有动态的方式?

I am implementing URI in OpenRasta for a resource in configuration file. This perticular resource is a child entity of multiple resources.
Parent and child is having one to many relation. All Parent Entities are having an int value via enum type in code.

Now I want to implement my URI like this :

{ParentEntityName}/{ParentId}/{ChildName}/{ChildId}

How can I implement this?? Do I need to make saperate configuration for each parent entity or there is a dynamic way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城旧梦 2024-12-27 14:20:13

您可以有一个处理程序来接受所有这些并以这种方式检索实体。

ResourceSpace.Has.ResourcesOfType<Childresource>()
                 .AtUri("{ParentEntityName}/{ParentId}/{ChildName}/{ChildId}")
                 .HandledBy<Handler>()

class Handler {
  public ChildResource Get(string parentEntityName, int parentId, string childName, int childId) { /*...*/ }
}

虽如此,如果孩子在服务器上有一个标识符,您只需将 URI 与 id 进行映射,就可以让事情变得更容易。

You can just have a handler that takes all this and retrieve the entity that way.

ResourceSpace.Has.ResourcesOfType<Childresource>()
                 .AtUri("{ParentEntityName}/{ParentId}/{ChildName}/{ChildId}")
                 .HandledBy<Handler>()

and

class Handler {
  public ChildResource Get(string parentEntityName, int parentId, string childName, int childId) { /*...*/ }
}

Now that said, if the child has an identifier on the server you can probably make things easier on yourself by just mapping the URI with an id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文