我是 openRasta 框架的新手。我有一个名为 Project 的资源。我要对此资源执行 2 种不同类型的 GET,因为我需要有关这两个 GET 的不同信息。我的配置如下所示,
ResourceSpace.Has.ResourcesOfType<IList<Project>>()
.AtUri("/projects")
.And.AtUri("/miniprojects")
.HandledBy<ProjectHandler>()
.AsJsonDataContract()
.And.AsXmlDataContract();
Handler 中的方法如下所示
[HttpOperation(HttpMethod.GET, ForUriName = "/projects")]
public OperationResult GetProjectsList()
{
}
[HttpOperation(HttpMethod.GET, ForUriName = "/miniprojects")]
public OperationResult GetMiniProjectList()
{
}
并且 此资源,无论我的 URL 是什么,例如 http://localhost/projects 或 http://localhost/miniprojects) 每次都会调用处理程序类中名称为 GetXXX 的第一个方法。当我更改处理程序文件中 GetXXX 方法的顺序时,会调用另一个方法。
所以我的问题是,Handler中的方法顺序是否决定了调用哪个GetXXX方法?此外,我在 HttpOperation 属性中为片段中提到的每个 GetXXX 方法指定了不同的“ForUriName”,但顺序仍然优先。
任何人都可以帮我解决这个问题吗?或者如果我遗漏了什么请告诉我。
提前致谢。
I am new to openRasta framework. I have a resource called Project.I have 2 different types of GET to be done on this resource as i need different info on these two GETs.My configuration is like this
ResourceSpace.Has.ResourcesOfType<IList<Project>>()
.AtUri("/projects")
.And.AtUri("/miniprojects")
.HandledBy<ProjectHandler>()
.AsJsonDataContract()
.And.AsXmlDataContract();
and my methods in Handler are as below
[HttpOperation(HttpMethod.GET, ForUriName = "/projects")]
public OperationResult GetProjectsList()
{
}
[HttpOperation(HttpMethod.GET, ForUriName = "/miniprojects")]
public OperationResult GetMiniProjectList()
{
}
Whenever i am doing some GET on this resource, whatever my URL is for example http://localhost/projects or http://localhost/miniprojects) the very first method with GetXXX name in handler class gets called every time. When I changed the sequence of the GetXXX methods in handler file the other method gets called.
So my question is, does sequence of methods in Handler determines which GetXXX method to be called? Moreover, I specified different "ForUriName" in the HttpOperation attribute for each GetXXX method as mentioned in the snippet, but still the sequence took the precedence.
Can any one help me in resolving this issue? Or let me know if I am missing anything.
Thanks in advance.
发布评论
评论(1)
如果无法区分两个 URI,那么我们根本不保证任何顺序。
如果您确实想以这种方式使用 URI 路由(而不是对不同的资源进行建模),那么您的 uri 需要使用名称进行注册。
命名位需要与属性相匹配
If threre is no way do make the distinction between two URIs then we don't guarantee any order at all.
If you really want to use URI routes in this way (as opposed to model different resources), then your uri needs to be registered with a name
The Named bit needs to match the attribute