我可以在 Open Rasta 中使用一个处理程序和一个 URI 注册多个资源吗? [英] Can I register multiple resources with one handler and one URI in Open Rasta?

查看:44
本文介绍了我可以在 Open Rasta 中使用一个处理程序和一个 URI 注册多个资源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个处理程序和一个 URI 注册多个资源.所以想确认这在 open rasta 中是否可行.我浏览了一些有关 open rasta 的网站,但无法断定这是否可行?

I want to register mutliple resources with one handler and one URI.so want to confirm that is this possible in open rasta. I have gone through a bit of websites regarding open rasta but couldn't able to conclude that whether this is possible or not?

  ResourceSpace.Has
           .ResourcesOfType<Request>()
           .AtUri("/processing")
           .HandledBy<SomeHandler>()
           .TranscodedBy<SomeCodec>();    

我需要处理从基类Request"派生的所有请求.如果有人能真正阐明这一点,那就太好了.

I need to handle all the request which are derived from the base class "Request". It would be great if some body could actually shed light on this.

推荐答案

在我相当有限的 OpenRasta 经验中,您可以使用 .And 方法添加额外的 .AtUri 资源位置.

In my fairly limited experience of OpenRasta you can use the .And method to add additional .AtUri resource locations.

即你的情况

ResourceSpace.Has
       .ResourcesOfType<Request>()
       .AtUri("/processing").And.AtUri("/processing/{processid}")
       .HandledBy<SomeHandler>()
       .TranscodedBy<SomeCodec>();  

其中 {curley 括号} 指定您的 Handler 方法的输入参数,即:

where the {curley brackets} specify the input parameter of your Handler method i.e.:

public class SomeHandler
{
    public Request Get(int processid = 0) //specify a default value for the uri case /processed
    {
        if (processid == 0)
            return Context.Set<Request>().ToList(); //Context comes from my DbContext derived class which is part of my entity model.
        else
            return GetRequestFromProcessId(processid) //this is a private method in your handler class using Linq to SQL to retreive the data your interested in.  I can't see your handler so I'm making it up.
     }
 } 

我在 OpenRasta 文档中找到了一个注释,其中指定您必须为每个匹配的类型和处理程序指定(只有一个)ResourceSpace 定义.换句话说,您不得使用相同的 HandledBy 处理程序类复制相同的 ResourceOfType 类.我对此进行了测试,情况确实如此,也许您首先要问这个问题.

I found in the OpenRasta documentation a note which specifed that you MUST have destinct (only one) ResourceSpace definition for each matching Type and Handler. In other words you must not duplicate the same ResourceOfType class with the same HandledBy handler class. I tested this and it is the case and perhaps why you are asking the question in the first place.

注意这段代码完全未经测试,我只是采用了我所写的模式,并在已知的类和 uri 中进行了替换.这还假设您正在尝试从 HTTP GET 动词检索数据.另一个贡献者,沿着 POST 路线走,但你没有指定.

N.b. this code is completely untested, I've just taken the patern of what I've written and substituted in your classes and uri where known. This also assumes you are trying to retrieve data from a HTTP GET verb. The other contributer, went down the POST route, but you haven't specified.

这篇关于我可以在 Open Rasta 中使用一个处理程序和一个 URI 注册多个资源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆